String
- The string class is non-modifiable, creating strings that need to be modified using StringBuffer (thread synchronization, higher security) or StringBuilder (thread is unsynchronized and faster).
- You can connect a string with "+".
- Creates a formatted string with String.Format ().
ArrayList
Stack
Queue
- is an interface that LinkedList implements the queue interface
- Common operation: Offer,peek,poll,isempty
Public Static voidqueuetest () {//LinkedList implements the queue interface, so it is constructed with LinkedListQueue<string> queue=NewLinkedlist<string>(); //increments the element at the end of the queue and returns whether it adds successSystem.out.println (Queue.offer ("abc"))); System.out.println (Queue.offer ("Def")); //returns the first element of the queue, which returns null if it is empty; (Ps:element throws an exception when the queue is empty)System.out.println (Queue.peek ()); //POPs the first element of the team and returns the first element of the team, returning null if the queue is emptySystem.out.println (Queue.poll ()); //determine if the queue is emptySystem.out.println (Queue.isempty ());}
LinkedList
- Doubly linked list, non-synchronous
- Common operation: Addfirst,addlast,add,getfirst,getlast,get,removefirst,removelast,remove,isempty
Public Static voidlinkedlisttest () {LinkedList<String> linkedlist=NewLinkedlist<string>(); //in the chain list head Plus, tail Plus, any position Canadian dollarLinkedlist.addfirst ("haha"); Linkedlist.addlast ("Yali"); Linkedlist.add (1, "good"); //Output Link ListSystem.out.println ("first element:" +Linkedlist.getfirst ()); System.out.println ("Last element:" +linkedlist.getlast ()); for(intI=0;i<linkedlist.size (); i++) System.out.println (Linkedlist.get (i)); //Delete any position, head, tail of the linked list elementLinkedlist.remove (1); Linkedlist.removefirst (); Linkedlist.removelast (); //determine if the linked list is emptySystem.out.println (Linkedlist.isempty ());}
HashMap
- Non-synchronous
Public Static voidhashmaptest () {HashMap<string, integer> hashmap=NewHashmap<string, integer>(); //adding elements to the hash tableHashmap.put ("TP", 123); Hashmap.put ("ZP", 567); System.out.println (HASHMAP); //facilitates a hash table with iterators for(Iterator<entry<string, Integer>> iterator=Hashmap.entryset (). iterator (); Iterator.hasnext ();) {Entry<string, integer> entry=Iterator.next (); System.out.println (Entry.getkey ()); System.out.println (Entry.getvalue ()); } //find if the key is in a hash tableSystem.out.println (Hashmap.containskey ("he"))); //find if the hash table has this valueSystem.out.println (Hashmap.containsvalue (567)); //Delete a key-value pair from a hash tableHashmap.remove ("TP"); System.out.println (HASHMAP);}
SUMMARY | Data structures in Java