Container classes in java: List
(list), Set
(set), Queue
(queue) , Map
(Map)
List (List): What we care about is the index. It is an interface, cannot instantiate objects, and can store repeated elements.
ArrayList (dynamic array):
List<String> l1=new ArrayList<String>(); l1.add("许远志"); l1.add("将最前"); l1.remove(0);
Recommended related learning video tutorials: java learning
Please see the example:
//遍历 for(String str:l1) { System.out.println(str); } for(int i=0;i<l1.size();i++) { System.out.println(l1.get(i)); } //LinkedList(链表)方便数组的插入操作 List<String> l2=new LinkedList<String>(); l2.add("许远志"); l2.add("许远志2"); l2.add("许远志3"); for(String str1:l2) { System.out.println(str1); } //Set(集):关心唯一性 对象无序存储 不能存储重复元素 Set<String> s1=new HashSet<String>(); s1.add("xuxu"); s1.add("yuan"); s1.add("zhi"); s1.remove("zhi"); for(String str:s1) { System.out.println(str); } //Map(映射)对象以键-值对应存储 key不允许有重复 value允许有重复 Map<String,String> m=new HashMap<String,String>(); m.put("apple","苹果"); m.put("book","书"); m.put("student","学生"); System.out.println(m.get("apple")); for(String key :m.keySet()) { System.out.println(key+":"+m.get(key)); }
java related article tutorial recommendation: java entry program
The above is the detailed content of What are the container classes in java. For more information, please follow other related articles on the PHP Chinese website!