UML demonstration of Java serialization 82Set, Collection, List, and Map

1. UML Demonstration Collection Collection Collection Inheritance Structure Diagram 2. Set collection 1. Characteristics of List storage elements: ordered and repeatable. In order, what is the order in which they are stored and what order they are taken out. 2. Characteristics of Set storage elements: unordered and non-repeatable. When they are stored in the same order, when they are taken out, they may not be in the original order. 3.SortedSet features Characteristics of storing elements: Unordered and non-repeatable, but the stored elements can be automatically sorted according to the size of the elements. 3. Introduction to the underlying data structure of commonly used collection classes 1. The bottom layer of ArrayList uses an array to store elements, so the ArrayList collection is suitable for querying, but not suitable for frequent random additions and deletions of elements. 2. The bottom layer of LinkedList uses a two-way linked list. This data structure stores data. Linked lists are suitable for frequent additions and deletions of elements, but are not suitable for query operations. 3. The bottom layer of Vector is the same as the ArrrayList collection, but Vector is thread-safe and less efficient, so it is rarely used now. 4. Map collection inheritance…

Traversal methods of Java collections Set, List, and Map

The examples in this article describe the traversal methods of Java collections Set, List, and Map, and share them with you for your reference. The specific methods are as follows: package com.shellway.javase; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; import org.junit.Test; public class TestCollection { public static void print(Collection c){ Iterator it = c.iterator(); while (it.hasNext()) { Object object = (Object) it.next(); System.out.println(object); } } @Test public void demo1(){ Set set = new HashSet(); set.add(“AAA”); set.add(“BBB”); set.add(“CCC”); print(set); //The first traversal method of Set: using Iterator Iterator it1 = set.iterator(); for (String ss : set) { System.out.println(ss); } //The first traversal method of Set: using foreach for (String sss : set) { System.out.println(sss); } List list = new ArrayList(); list.add(“DDDDD”); list.add(“EEEEE”); list.add(“FFFFF”); print(list); //The first traversal method of List: because the list has order, use the size() and get() methods to obtain for (int i = 0; i <list.size(); i++) { System.out.println(list.get(i)); } //The second way to traverse List: using Iterator Iterator it = list.iterator(); while (it.hasNext()) { System.out.println(it.next()); } //The third way to traverse List: using foreach for (String s2 : list) { System.out.println(s2); } Map map = new TreeMap();…

UML demonstration of Java serialization 82Set, Collection, List, and Map

1. UML Demonstration Collection Collection Collection Inheritance Structure Diagram 2. Set collection 1. Characteristics of List storage elements: ordered and repeatable. In order, what is the order in which they are stored and what order they are taken out. 2. Characteristics of Set storage elements: unordered and non-repeatable. When they are stored in the same order, when they are taken out, they may not be in the original order. 3.SortedSet features Characteristics of storing elements: Unordered and non-repeatable, but the stored elements can be automatically sorted according to the size of the elements. 3. Introduction to the underlying data structure of commonly used collection classes 1. The bottom layer of ArrayList uses an array to store elements, so the ArrayList collection is suitable for querying, but not suitable for frequent random additions and deletions of elements. 2. The bottom layer of LinkedList uses a two-way linked list. This data structure stores data. Linked lists are suitable for frequent additions and deletions of elements, but are not suitable for query operations. 3. The bottom layer of Vector is the same as the ArrrayList collection, but Vector is thread-safe and less efficient, so it is rarely used now. 4. Map collection inheritance…

UML demonstration of Java serialization 82Set, Collection, List, and Map

1. UML Demonstration Collection Collection Collection Inheritance Structure Diagram 2. Set collection 1. Characteristics of List storage elements: ordered and repeatable. In order, what is the order in which they are stored and what order they are taken out. 2. Characteristics of Set storage elements: unordered and non-repeatable. When they are stored in the same order, when they are taken out, they may not be in the original order. 3.SortedSet features Characteristics of storing elements: Unordered and non-repeatable, but the stored elements can be automatically sorted according to the size of the elements. 3. Introduction to the underlying data structure of commonly used collection classes 1. The bottom layer of ArrayList uses an array to store elements, so the ArrayList collection is suitable for querying, but not suitable for frequent random additions and deletions of elements. 2. The bottom layer of LinkedList uses a two-way linked list. This data structure stores data. Linked lists are suitable for frequent additions and deletions of elements, but are not suitable for query operations. 3. The bottom layer of Vector is the same as the ArrrayList collection, but Vector is thread-safe and less efficient, so it is rarely used now. 4. Map collection inheritance…

UML demonstration of Java serialization 82Set, Collection, List, and Map

UML demonstration of Java serialization 82Set, Collection, List, and Map

1. UML Demonstration Collection Collection Collection Inheritance Structure Diagram 2. Set collection 1. Characteristics of List storage elements: ordered and repeatable. In order, what is the order in which they are stored and what order they are taken out. 2. Characteristics of Set storage elements: Unordered and non-repeatable. When they are stored in the same order, when they are taken out, they may not be in the original order. 3.SortedSet features Characteristics of storing elements: Unordered and non-repeatable, but the stored elements can be automatically sorted according to the size of the elements. 3. Introduction to the underlying data structure of commonly used collection classes 1. The bottom layer of ArrayList uses an array to store elements, so the ArrayList collection is suitable for querying, but not suitable for frequent random additions and deletions of elements. 2. The bottom layer of LinkedList uses a two-way linked list. This data structure stores data. Linked lists are suitable for frequent additions and deletions of elements, but are not suitable for query operations. 3. The bottom layer of Vector is the same as the ArrrayList collection, but Vector is thread-safe and less efficient, so it is rarely used now. 4. Map collection inheritance…

Introduction to JAVAList, Set, and Map

Before writing this article, I would like to first thank Chuanzhi Podcast – because of their selflessness, we have many high-quality learning videos. Let’s get to the point – introduce List, Set, and Map. First of all, List and Set are subclasses of Collection. So first introduce the Collection collection 1. Collection (Collection) (1) The origin of collections? What we learn is Java – object-oriented – operating many objects – storage – container ( Arrays and StringBuffer) — Arrays and arrays have a fixed length – so they are not suitable for changing needs – Java provides collections for us to use. (2) What is the difference between a collection and an array? A: The difference in length is that the array is fixed and the collection is variable. B: The difference in content is that the array can be a basic type or a reference type. The collection can only be a reference type. C: the element content array can only store elements. The same type of collection can store different types (in fact, collections generally store the same type) (3) Inheritance architecture of collections? Due to different needs, Java provides different collection classes. The data structures of these…

Java basics – simple operations and traversal of List, Set, and Map

The first:List [three iteration methods] public class ListTest { ArrayList< String > list1= new ArrayList<String>();public ArrayList <String> addMethod(){for ( int i = 0; i < 9; i++) {list1.add(i&#43 ;””);}return list1; }public ArrayList<String> deleteMethod(){list1.remove( “5”);return list1 ;}public ArrayList<String> updateMethod(){list1.set (1,”5″);return list1;}/** Iterator traversal*/ public void selectMethod1(){Iterator <String>it=list1.iterator ();while(it.hasNext()){String string=it.next();System.out.print(string& #43;”\t”);}}/** foreach() method traversal*/public void selectMethod2(){for(String s:list1){System .out.print(s+”\t”);}}/* * for() method traversal */public void selectMethod3 (){for (int i &# 61; 0; i < list1 .size(); i++) {System. out.print(list1.get(i)+”\t”);}} public static void main(String[ ] args) {ListTest list1=new ListTest();System.out.print(list1.addMethod()+”\t” );list1.selectMethod1();System.out.println(); System.out.print(list1.deleteMethod()+”\t”);list1.selectMethod2();System.out.println() ;System.out.print(list1.updateMethod()+”\t”);list1.selectMethod3();}} Second:Set [Two iteration methods] public class SetTest {HashSet<String> set1 =new HashSet<>();public HashSet<String> addMethod(){set1.add(“aaa”);set1.add(“bbb”);set1.add(” ccc”);return set1;}public HashSet<String> deleteMethod(){set1.remove(“aaa”);return set1;} public HashSetreturn map;} public Map<String,String> deleteMethod() {map.remove(“001”);return map;}public Map<String,String> updateMethod(){map.remove(“002”); map.put(“001″,”Erha”);return map;}/** Iterator traversal*/public void selectMethod(){Iterator <String> it=map.keySet( ).iterator();while span>(it.hasNext()){String s1=it. next();String name=map .get(s1);System.out.println(s1+”\t”+name);}}public void selectMethod1( ){/** foreach() method traversal*/for (Map .Entry<String, String> entry : map.entrySet ()){System.out.println(entry.getKey() + “\t” + entry.getValue());}} public static void main(String[ ] args) {MapTest map1=new MapTest();System.out.print(map1.addMethod()+”\t” );map1.selectMethod();System.out.println(); System.out.print(map1.deleteMethod()+”\t”);map1.selectMethod();System.out.println() ;System.out.print(map1.updateMethod()+”\t”);map1.selectMethod1();}} class=”token generics”><String, String> entry : map.entrySet()){System.out.println(entry.getKey() + “\t” + entry.getValue());}}public static void main(String[] args) {MapTest map1&# 61;new MapTest( );System.out.print(map1.addMethod()+“\t”);map1.selectMethod();System.out.println ();System.out.print(map1.deleteMethod()+“\ t”);map1.selectMethod() ;System.out. println();System.out.print(map1.updateMethod()+“\t”);map1.selectMethod1( );}} ode>

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索