Results 1 to 3 of 3
Thread: Collection Help
- 03-18-2011, 08:32 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 6
- Rep Power
- 0
Collection Help
Hi All,
I have a program Like this
public class sample {
public static void main(String[] args) {
Collection<Map<String, String>> collectionMap = getCollectionMap();
Map<String, Map<String, String>> map = new HashMap<String, Map<String, String>>();
Map<String, String> insideMap = new HashMap<String, String>();
insideMap.put("1", "A");
insideMap.put("2", "B");
map.put("Map1", insideMap);
map.put("Map2", insideMap);
collectionMap.addAll(map.values());
System.out.println(collectionMap);
}
private static Collection<Map<String, String>> getCollectionMap() {
TreeMap<String, Map<String, String>> treeMap = new TreeMap<String, Map<String, String>>();
Map<String, String> insideMap = new HashMap<String, String>();
insideMap.put("1", "A");
insideMap.put("2", "B");
treeMap.put("Map1", insideMap);
treeMap.put("Map2", insideMap);
return treeMap.values();
}
I get an error
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractCollection.add(Unknown Source)
at java.util.AbstractCollection.addAll(Unknown Source)
at sample.main(sample.java:209)
in the Line collectionMap.addAll(map.values());
could anybody help me in this?
Thanks,
Guru
- 03-18-2011, 08:42 AM #2
Do you want to add all values of map to collectionMap
sanjeev,संजीव
- 03-18-2011, 09:18 AM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Help me on Collection
By kathir0301 in forum New To JavaReplies: 1Last Post: 12-03-2010, 11:08 AM -
collection
By D.Calladine in forum New To JavaReplies: 1Last Post: 12-02-2010, 02:36 PM -
java collection api
By rajinder5 in forum Advanced JavaReplies: 1Last Post: 10-07-2010, 01:51 PM -
help for collection api
By javastuden in forum New To JavaReplies: 3Last Post: 02-24-2010, 11:52 AM -
how to creat collection
By STILET in forum Advanced JavaReplies: 2Last Post: 07-29-2008, 07:17 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks