Problem in collections:

I am having a a problem here:

Map<Integer, String> map = new ArrayList<Integer, String>();

Collection<Integer> keys = map.keySet();

for(String id : categories) {

if(Collections.binarySearch(keys, Integer.valueOf(id)) > 0) { some code...}

}

While compiling i am getting the following compile time error:

AuthorProfileSaveEditAction.java:165: cannot find symbol

symbol : method binarySearch(java.util.Collection<java.lang.Integer>,java.lang.Integer)

location: class java.util.Collections

if(Collections.binarySearch(keys, Integer.valueOf(id)) > 0) {}

^

Can anyone help...

[679 byte] By [Nistelrooy] at [2007-11-26 12:16:02]
# 1
binarySearch takes a List as argument, not a Collection.Kaj
kajbj at 2007-7-7 14:51:31 > top of Java-index,Archived Forums,Socket Programming...
# 2
I think this statement is also causing trouble:Map<Integer, String> map = new ArrayList<Integer, String>();You can't convert ArrayList to Map and ArrayList doesn't have a 2 argument constructor. You are mixing 4 types of collections!
Peetzore at 2007-7-7 14:51:31 > top of Java-index,Archived Forums,Socket Programming...
# 3

Use Map<Integer, String> map = new HashMap<Integer, String>();

for(String id : categories) {

if(map.containsKey(Integer.valueOf(id)))

{

some code...

}

}

Peetzore at 2007-7-7 14:51:31 > top of Java-index,Archived Forums,Socket Programming...
# 4
Thanks a lot dear..
Nistelrooy at 2007-7-7 14:51:31 > top of Java-index,Archived Forums,Socket Programming...