I recently reviewed java when I was looking for a job. After reading the books and online textbooks, I found that although many books use java to talk about data structures, they focus on the knowledge of data structures, using java class libraries to implement data structures is rarely explained in a systematic manner, so I would like to make a summary here to make it easier for anyone who is preparing and using java to implement data structures.
// Stack
Stack <String> st = new Stack <String> ();
// Stack <Integer> st = new Stack <Integer> ();
St. push ("1a ");
St. push ("2b"); www.2cto.com
St. push ("3c ");
St. push ("4d ");
System. out. println ("pop is:" + st. pop ());
System. out. println ("size is:" + st. size ());
System. out. println ("peek is:" + st. peek ());
System. out. println ("isEmpty is:" + st. isEmpty ());
System. out. println ("toString is:" + st. toString ());
System. out. println ();
// Queue
Queue <String> qu = new Queue list <String> (); // wrong: Queue <String> qu = new Queue <String> ();
Qu. add ("1a ");
Qu. add ("2b ");
Qu. add ("3c ");
Qu. add ("4d ");
// Qu. offer ("4d"); // equal to add, but no exception
System. out. println ("remove is:" + qu. remove ());
// System. out. println ("poll is:" + qu. poll (); // equal to remove, but no exception
System. out. println ("peek is:" + qu. peek ());
System. out. println (qu. toString ());
System. out. println ();
// Link list: webmaster Center
Shortlist <String> head = new shortlist <String> ();
Head. add ("1 ");
Head. add ("3 ");
Head. add (1, "2 ");
// The volume table will automatically print all content in the "repeated" mode.
System. out. println (head );
System. out. println ("size is:" + head. size ());
// Add data to the orders table using collections such as Vector or ArrayList
Vector <String> v = new Vector <String> (); // need to import java. util. Vector;
// Add things to the Vector
V. add ("");
V. add ("B ");
// Add the prefix Vector to the end of the forward vertex table.
Head. addAll (v );
System. out. println (head );
// Add the prefix Vector to the specified position of the pre-increment table
Head. addAll (2, v );
System. out. println (head );
// Print the content at the specified position
System. out. println ("get (2) is:" + head. get (2 ));
System. out. println ("index is:" + head. indexOf (head. get (2 )));
Head. addFirst ("fist ");
Head. addLast ("last ");
System. out. println (head );
// Remove the first
Head. remove (head. getFirst ());
Head. remove (head. getLast ());
System. out. println (head );
// Remove the first one and use the lower-level method. The lower-level starts from 0.
Head. remove (0 );
System. out. println (head );