Nonsense not much to say, on the code:
Packagecom.core.test;Importjava.util.ArrayList;ImportJava.util.HashMap;Importjava.util.List;ImportJava.util.Map; Public classObjectlisttest { Public Static voidMain (string[] args) {Object obj=Createmap (); if(objinstanceofMap) {Map<String,Object> map =(Map) obj; System.out.println (Map.get ("Name")); } Object obj1=createlist (); if(obj1instanceofList) {List<String> list =(List) obj1; for(inti = 0; I < list.size (); i++) {System.out.println (List.get (i)); } } } Public StaticMap<string,object>Createmap () {Map<string, object> map =NewHashmap<string, object>(); Map.put ("Name", "Zhang Fei"); Map.put ("Age", "10"); returnmap; } Public StaticList<string>createlist () {List<String> list =NewArraylist<string>(); for(inti = 0; I < 10; i++) {List.add ("Bu" +i); } returnlist; } }
Results:
Zhang Fei bu 0 lv bu 1 lv bu 2 bu 3 lv bu 4 bu 5 lv bu 6 bu 7 bu 8 lv bu 9
The Java object class is the one that can receive the collection type