arraylist Questions
6
Solved
I was asked the following question in an interview. How can I sort a Dictionary by the key, in the order which is in an array list.
So for example I have a dictionary as follows
Dictionary<s...
Clutch asked 23/4, 2014 at 21:45
35
Solved
I wanted to create a list of options for testing purposes. At first, I did this:
ArrayList<String> places = new ArrayList<String>();
places.add("Buenos Aires");
places.add("Córdoba");
...
Meaningful asked 17/6, 2009 at 4:10
16
Solved
I use a lot of lists and arrays but I have yet to come across a scenario in which the array list couldn't be used just as easily as, if not easier than, the linked list. I was hoping someone could ...
Tarango asked 26/12, 2008 at 6:52
5
I am trying to do a batch-insert of a collection of beans. One of the properties of the bean is an ArrayList. The batch update fails with the exception:
Can't infer the SQL type to use for an ins...
Miranda asked 3/7, 2014 at 12:20
34
Solved
I've always been one to simply use:
List<String> names = new ArrayList<>();
I use the interface as the type name for portability, so that when I ask questions such as this, I can rewor...
Pestalozzi asked 27/11, 2008 at 1:36
34
Solved
I've always been one to simply use:
List<String> names = new ArrayList<>();
I use the interface as the type name for portability, so that when I ask questions such as this, I can rewor...
Sophistic asked 27/11, 2008 at 1:36
34
Solved
I've always been one to simply use:
List<String> names = new ArrayList<>();
I use the interface as the type name for portability, so that when I ask questions such as this, I can rewor...
Frankly asked 27/11, 2008 at 1:36
13
Solved
What is the simplest way to reverse this ArrayList?
ArrayList<Integer> aList = new ArrayList<>();
//Add elements to ArrayList object
aList.add("1");
aList.add("2");
aList.add("3");
aL...
Gera asked 26/5, 2012 at 13:5
5
Solved
I have the following qustion:
How can I convert the following code snipped to Java 8 lambda style?
List<String> tmpAdresses = new ArrayList<String>();
for (User user : users) {
tmpAd...
Carrew asked 8/8, 2018 at 13:14
18
Solved
You can set the initial size for an ArrayList by doing
ArrayList<Integer> arr=new ArrayList<Integer>(10);
However, you can't do
arr.add(5, 10);
because it causes an out of bounds ...
Minium asked 17/1, 2012 at 14:56
2
Solved
I have following code which seems to be causing some memory leaks. This code snippet(i.e. hasPermissions()) get executed every time when a user performs an action.
So from what I understood, since ...
Lacrimatory asked 2/10, 2023 at 1:43
2
Solved
How to get the last item of an ArrayList in kotlin?
I have a list like
val myList = listOf("item1", "item2", "item3")
I want to get the last item of myList
3
Solved
I've been tasked to do the below in a newbie Java tutorial on ArrayList
// 1) Declare am ArrayList of strings
// 2) Call the add method and add 10 random strings
// 3) Iterate through all the el...
5
Solved
I have an ArrayList with custom objects that I would like to be able to save and restore on a screen rotate.
I know that this can be done with onSaveInstanceState and onRestoreInstanceState if I ...
Roturier asked 19/9, 2012 at 22:34
20
Solved
I'm trying to convert an ArrayList containing Integer objects to primitive int[] with the following piece of code, but it is throwing compile time error. Is it possible to convert in Java?
List<...
Orelia asked 5/4, 2009 at 7:59
16
Solved
I need to add elements to an ArrayList queue whatever, but when I call the function to add an element, I want it to add the element at the beginning of the array (so it has the lowest index) and if...
7
Solved
I have an ArrayList which is filled by Objects.
My object class called Article which has two fields ;
public class Article {
private int codeArt;
private String desArt;
public Article(int aI...
3
I would like to know what is the difference between array (arrayOf), list (listOf), and arraylist (arrayListOf) in Kotlin? and how to use them in appropriate way? Thank you.
3
Solved
I want to remove the last object from an ArrayList quickly.
I know that remove(Object O) takes O(n) in an ArrayList, but I wonder if it is possible to do this in constant time since I just want to...
Gavette asked 7/6, 2013 at 15:27
6
Solved
In Java, ArrayList and HashMap are used as collections. But I couldn't understand in which situations we should use ArrayList and which times to use HashMap. What is the major difference between bo...
Sumatra asked 7/3, 2010 at 9:46
9
Solved
There is probably a simple one-liner that I am just not finding here, but this is my question:
How do I check if an ArrayList contains all of the objects in another ArrayList? I am looking (if it ...
Fraenum asked 24/1, 2013 at 22:5
7
Solved
is there any way to check if a collection contain a value or more with better performance than looping twice with contains?
in other meaning something that would look like this
person.contains("...
Aldehyde asked 24/12, 2013 at 5:38
6
I am trying to sort an ArrayList of Strings that represent card values. So, some cards contain letters ("King") and some contain Strings containing only a number ("7"). I know to use Collections.so...
Derisible asked 8/6, 2010 at 16:9
5
I made a Stack and an ArrayList to make a research. Actually I want now to make my Stack replaced by an ArrayList, but how to transform a Stack into an ArrayList ? How is it going with push, pop .....
7
Solved
I tried to create a list of maps. In the following code, I'm expecting to get
[{start=1,text=ye}, {start=2,text=no}]
however, I only got
[{start=2,text=no}, {start=2,text=no}]
How to avoid o...
© 2022 - 2025 — McMap. All rights reserved.