get indices from arraylist
in
Programming Questions
•
2 years ago
hi i have written a function to get the arraylist`s index values that contain the number occurrences of each state.The csv file is 24499 rows and 3 columns
the strange thing is that i get the number of occurrences correct for all states but the index values are correct *only* for two states (i get no values (a blank [] ) for the rest of the states)...anyone has an idea why this might be happening?
its the first time i use collections etc, is this the correct way to do something like this?...what i want to do (if it helps) is get the index values,store them in an array and then for these values draw some points with csv[indexValues][1] and csv[indexValues][2]
last thing: is it possible to write functions like
Arraylist something(){
//blabla
} return somethingElse;
without using generics?
- String [] states=new String [24499];
String [] stateNames(){
for (int i=0; i<data.length; i++){
states[i]=csv[i][0];
}
return states;
} - //in this function s is a string that holds one state name with a leftClick mouseFunction
- void indices(){
- int occurences=0;
- List myList=Arrays.asList(stateNames()); //
- Iterator iterator=myList.iterator();
- while(iterator.hasNext()){
- println((String) iterator.next()); //it breaks without this line(?)
- }
- if (myList.contains(s)){
- occurences=Collections.frequency(myList,s);
- }
- List<Integer> indices=new ArrayList<Integer>(occurences);
- for (int i=0; i<occurences; i++){
- if(s.equals(myList.get(i))){
- indices.add(i);
- }
- }
- print(s+" "+occurences+" " );
- println(indices);
- }
the strange thing is that i get the number of occurrences correct for all states but the index values are correct *only* for two states (i get no values (a blank [] ) for the rest of the states)...anyone has an idea why this might be happening?
its the first time i use collections etc, is this the correct way to do something like this?...what i want to do (if it helps) is get the index values,store them in an array and then for these values draw some points with csv[indexValues][1] and csv[indexValues][2]
last thing: is it possible to write functions like
Arraylist something(){
//blabla
} return somethingElse;
without using generics?
1