The basic collection of Java is very important and very detailed, collection, list, set, map. The path to growth as a programmer.

Collection: 1. Understanding and benefits of collection: 1. Array: (1) The length must be specified at the beginning, and once created, it cannot be changed; ( 2) The elements saved must be of the same type; (3) The schematic code for enhancing/deleting elements using data rent – comparison and placement //Write the schematic code for Person array expansion: Person[] pers = new Person[1];//The size is 1per(0) = new

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>

[Java Basics Consolidation Series] Java data collections, List, Map, Set, JUC, everything you need

Popular Series: [Java Basics Consolidation Series] Java Memory Overflow and Memory Leak [Java Basics Consolidation Series] Java class initialization execution sequence [Java Basics Consolidation Series] The most comprehensive technical architecture mind map for advanced Java advancement [Java Basics Consolidation Series] Understanding Java Parental Delegation Mechanism Programming Life,Wonderful Preview Table of contents 1. Preface 2. Collection framework 3 .Set interface 3.1 The difference between Set and List 4. Commonly used collection implementation classes 4.1 ArrayList 4.2 LinkedList 4.3 HashMap 4.4 HashTable 4.5 ConcurrentHashMap 4.6 TreeMap 4.7 HashSet 5 .Five commonly used concurrency packages 5.1 ConcurrentHashMap 5.2 CopyOnWriteArrayList 5.3 CopyOnWriteArraySet 5.4 ArrayBlockingQueue 5.5 LinkedBlockingQueue 6. Summary 1. Preface Data storage includes a variety of data structures. But overall it can be divided into four categories: linear tables, hash trees, and graphs. And our java actually also has its own commonly used “data structure” – that is, collections. But the underlying implementation of collections in Java is also implemented by data structures such as arrays, linked lists, and trees. Below we will give a certain in-depth explanation of some commonly used collections. 2. Collection framework As a Java developer, you must know all the commonly used collections. Let’s use a picture to list…

hot3.png

Threading issues with List, Set, Map, and Queue in java

2019 Unicorn companies spend heavily to recruit Python engineers>>> Collections and Concurrent are both tool classes used by Java to assist and – designed to complete certain special and easily repeatable tasks,Or some relatively solved problems. In Java, the commonly used data structures are basically divided into three categories: Map, List, and Set. Thread-safe collection The Collection framework introduced in JDK 1.2 is a highly flexible framework for representing object collections – it uses the basic interfaces List, Set and Map. Multiple implementations of each collection – HashMap, Hashtable, TreeMap, WeakHashMap, HashSet, TreeSet, Vector, ArrayList, LinkedList, etc. – are provided through the JDK. Some of these collections are already thread-safe – Hashtable and Vector – through synchronized packaging factories – Collections.synchronizedMap(), synchronizedList() and synchronizedSet() – xff0c;The rest of the collection can be rendered thread-safe. The java.util.concurrent package adds several new thread-safe collection classes – ConcurrentHashMap, CopyOnWriteArrayList and CopyOnWriteArraySet. The purpose of these classes is to provide high-performance, highly scalable, thread-safe versions of basic collection types. Thread collections in java.util still have some drawbacks. For example, when iterating over a lock, you usually need to keep the lock in the collection, otherwise you risk throwing a ConcurrentModificationException. (This feature is sometimes…

Java collection List, Set, Map, Queue, Deque

Java collection List, Set, Map, Queue, Deque

Collections are a very important part of the foundation of Java,Java provides a very rich collection API,Understand the characteristics of each collection,How to use the correct collection in various scenarios “Very important” is also the most basic quality of a Java programmer. Overall understanding The most basic and most commonly used collections in Java are mainly “Set” and “List” ;Map,Queue,Deque. Collection is the top-level interface of the collection List,Set,Queue. Collection inherits from the Iterable interface to implement traversal of elements. The relationship between each class or interface is as shown in the following class diagram: List List is an ordered collection interface, inherited from Collection, has three implementation classes,ArrayList,LinkedList&#xff0c ;Vector, each has its own characteristics. ArrayList,The bottom layer is implemented through arrays,Elements have subscripts,Randomly reading elements through subscripts is highly efficient,The query time complexity is O(1). The disadvantage is that “when inserting or deleting elements”, “need to move elements” or when the array storage space is insufficient, “array expansion” is relatively expensive. In summary, ArrayList is suitable for finding and traversing elements but not for inserting and deleting elements. And ArrayList is thread-unsafe. LinkedList,The bottom layer is implemented through a linked list,Elements have no subscripts,Suitable for dynamic insertion and deletion…

Relevant commands for PHP to operate RedisLIST, SET, HASH (1)

Please visit the blog to move Related commands for PHP to operate Redis LIST, SET, HASH (1) Related commands for PHP to operate Redis KEY, String (2) Related commands for PHP to operate Redis ordered sets (Sorted Set) (3)

STL basic container: is string, vector, list, deque, set, map_string[] ordered?_cy941228’s blog

class=”markdown_views prism-atom-one-dark”> Basic containers in STL are: string, vector, list, deque, set, map set and map are unordered storage elements, which can only be accessed through the interface it provides set: collection, used to judge whether an element is in a group, less used map: mapping, equivalent to a dictionary, mapping one value to another value, if you want to create a dictionary, use it’s alright string, vector, list, deque, set are ordered containers 1.string string is the implementation of basic_string, and it is stored continuously in memory. In order to improve efficiency, there will be reserved memory, such as string s= “abcd”, then the space used by s may be 255, when string is inserted into s again When adding content, memory will not be allocated again. It will not apply for memory again until the content is > 255, thus improving its performance. When the content is > 255, string will first allocate a new memory, and then copy the content over , and then copy the previous content. The operation on string, if it is added to the end, generally does not need to allocate memory, so the performance is the fastest; If it is an operation…

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
首页
微信
电话
搜索