Originally Posted by
copeg
Its up to you, but once again I encourage you to use a Set or Map. This is their purpose. A short demo:
public class Test{
/**
*Analyzes the speed of list versus set searches
*/
public static void main(String[] args){
final int max = 10000;
ArrayList<String> list = new ArrayList<String>(max);
Set<String> set = new HashSet<String>(max);
//First populate the list and set with identical values
for ( int i = 0; i < max; i++ ){
list.add(Integer.toString(i));
set.add(Integer.toString(i));
}
long start = System.currentTimeMillis();
//search the list max number of times
for ( int i = 0; i < max; i++ ){
int num = (int)(Math.random() * max);
list.indexOf(Integer.toString(num));
}
System.out.print("Time to search list: ");
System.out.println(System.currentTimeMillis() - start);
start = System.currentTimeMillis();
//search the set max number of times
for ( int i = 0; i < max; i++ ){
int num = (int)(Math.random() * max);
set.contains(Integer.toString(num));
}
System.out.print("Time to search set: ");
System.out.println(System.currentTimeMillis() - start);
}
}
On my system:
Time to search list: 531
Time to search set: 0
Just my .02
On my crazy slow work computer (takes about 40 seconds to open a new tab in IE and 40 seconds to open the excel sheet I'm working on) it takes me 313 milliseconds to run the code I have now.
I know its not 10000 x 10000 elements, but the miliisecond difference doesnt justify rediting the code for all of 15 sheet entries again.