I'm storing data in a HashMap with (key: String, value: ArrayList). The part I'm having trouble with declares a new ArrayList "current," searches the HashMap for the String "dictCode," and if found sets current as the returned value ArrayList.
ArrayList current = new ArrayList();
if(dictMap.containsKey(dictCode)) {
current = d...
I'm trying to figure out the best way to search a customer in an ArrayList by its Id number. The code below is not working; the compiler tells me that I am missing a return statement.
Customer findCustomerByid(int id){
boolean exist=false;
if(this.customers.isEmpty()) {
return null;
}
for(int i=0;i<this.custome...
Hello
I have an ArrayList in Java which is made up of a type containing two strings and an integer. I can successfully test if one element of this ArrayList equals another but I find that the contains method fails. I believe this is due to the fact that my type is not primitive.
Now I see two alternatives to this and I wonder which is ...
I am willing to create a list of options to test something.
I was doing:
ArrayList<String> places = new ArrayList<String>();
places.add("Buenos Aires");
places.add("Córdoba");
places.add("La Plata");
I refactor the code doing:
ArrayList<String> places = new ArrayList<String>(Arrays.asList("Buenos Aires", "Córdoba", "La Plata"));
I...
Imagine that I need to create a Collection of elements, where order could or could not matter. Effectively all I plan on doing is using the iterator. I notice most of my colleagues using an ArrayList vs LinkedHashSet/HashSet. My question is, if I know that these elements should be unique, should I be using a Set or a List? Effectively it...
I have one million rows of data in .txt format. the format is very simple. For each row:
user1,value1
user2,value2
user3,value3
user1,value4
...
You know what I mean. For each user, it could appear many times, or appear only once (you never know). I need to find out all the values for each user. Because user may appear randomly, I u...
When I press f12 on the ArrayList keyword to go to metadata generated from vs2008, I found that the generated class declaration as follows
public class ArrayList : IList, ICollection, IEnumerable, ICloneable
I know that the IList already inherits from ICollection and IEnumerable, so why does ArrayList redundantly inherit from these in...
ArrayList<ArrayList<Integer>> a = new ArrayList<ArrayList<Integer>>(5);
for (int i = 0 ; i < a.size() ; i++){
a.set(i, new ArrayList<Integer>(10));
}
System.out.println(a.get(a.size()-1).get(9)); //exception thrown
The above snippet throws an exception in the printing part. Why?
...
I am trying to retrieve the correct value from an ArrayList of objects (1.1 Framework) :
I have the following defined :
Public AlList As New ArrayList
Public Class ItemInfo
Public ItemNo As Int16
Public ItemType As String
Public Reports As Array
Public PDFs As Array
End Class
The form_load event code contains :
Dim ...
how to get a column of recordset in an arraylist ?? using vb.net .. please help me out ..
...
Is there a more elegant solution to convert an 'Arraylist' into a 'Arraylist<Type>'?
Current code:
ArrayList productsArrayList=getProductsList();
ArrayList<ProductListBean> productList = new ArrayList<ProductListBean>();
for (Object item : productsArrayList)
{
ProductListBean product = (ProductListBean)item;
productList.add(produc...
I am writing a deserialization method that converts xml to a Java object. I would like to do this dynamically and avoid writing hard coded references to specific types.
For example this is a simplified version of one of my classes.
public class MyObject {
public ArrayList<SubObject> SubObjects = new ArrayList<SubObject>();
}
Her...
C++ has std::vector and Java has ArrayList, and many other languages have their own form of dynamically allocated array. When a dynamic array runs out of space, it gets reallocated into a larger area and the old values are copied into the new array. A question central to the performance of such an array is how fast the array grows in siz...
I am binding an ArrayList() to a Listbox control and assigning out an Displaymember and Value on data in the Array. My problem is that I Bind on startup but the Array gets filled after a few function calls. I have code on selectedIndexChanged to check the selectedValue but if the ArrayList is empty it returns an object, once it has data ...
Is there some way to use IComparer with ArrayList.Sort() to sort a group of strings as ints?
...
I have a program where I need to make 100,000 to 1,000,000 random-access reads to a List-like object in as little time as possible (as in milliseconds) for a cellular automata-like program. I think the update algorithm I'm using is already optimized (keeps track of active cells efficiently, etc). The Lists do need to change size, but tha...
Do I really need to implement it myself?
private void shrinkListTo(ArrayList<Result> list, int newSize) {
for (int i = list.size() - 1; i >= newSize; --i)
list.remove(i);
}
...
I have an arraylist of objects, I would like to know the index within the arraylist of the object that contains a certain value, is there a built-in way to do the search?
I know I could simply iterate through the arraylist to find the correct value e.g. :
ReportToFind="6"
For i = 0 To ReportObjList.Count - 1
If ReportObjList.Item(...
So, this is an efficiency question.
I have two collections - an ArrayList and a Stack. I use the stack because I needed some simple pop/push functionality for this bit of code. The ArrayList is essentially the out variable as this is a small section of code in the function.
So, I the variables are defined as such, then code is run to ...
Hi! My question is: what is wrong with this conversion?
public int getTheNumber(int[] factors) {
ArrayList<Integer> f = new ArrayList(Arrays.asList(factors));
Collections.sort(f);
return f.get(0)*f.get(f.size()-1);
}
I made this after reading solution found in http://stackoverflow.com/questions/157944/how-to-create-array...