-
/**I only talk about ListArray, ListedList, HashMap
//ListArray It is a class that implements the List interface. List inherits the collection interface.
//Call the import java.util.ArrayList package, (choose one of the two here) The complete java collection is stored in the java.util package
//Features:
1>.List is an ordered collection
2>.List can have duplicate element values
3>. Use indexes to accurately access element values,
4>.List can accurately control the insertion position of each element
//advantage
1>. It implements dynamic arrays and has high efficiency in traversing elements and randomly accessing elements (the following is an example of traversing elements).
1. List and ListArray syntax. Note that I use String type data. You can customize the object.
List list= new ListArray();
//Add an element
String str="123";
list.add(str); //The starting position starts from 0 and returns a Boolean value
//Return the number of elements in the collection
list.size(); //Return int type
//Get the value based on the index and return the ObjecL type
String s=(String)list.get(0);//The int type index is passed in. Here I use the String type, which needs to be converted.
//Add the specified element at the specified index
list.add(1,"123456"); //Note that you cannot add 2 elements before adding 1 element, which will cause an exception at runtime.
// Check if the element exists
list.contains(str); //Return Boolean type data
//Delete element
list.remove(str); //Return Boolean type data
/****Traverse ListArray******/
for(int i=0; i<list.size();i++){
System.out.println(list.get(i));
}
2. List and LinkedList classes
// grammar:
LinkedList listed= ne LinkedList();
String c="123";
String b="123";
String e="123";
//Add elements
1>Add head element
listed.addFirst(c);
2>Add tail elements
listed.addLast(b);
//Get elements
1>Get the first element
String st=(String) listed.getFist();
2>Get the tail element
String st1 =(String) listed.getLast();
//Delete element
1>Delete the first element
listed.removeFisrst();
2>Delete the tail element
listed.removeLast();
*******ListedList also has the method of ListArray******
should be created like this
List list= new ListedList(); //This only uses methods in ListArray
ListedList liste= (ListedList)list; //This way you have the methods in ListArray and listedList
listed
3. The Map interface and HashMap class have nothing to do with the above.
//Features:
1>Have keys and values
2>Easy to find
3>The value can be found by key
4>Do not add the same key value, otherwise it will be overwritten
grammar
Map map = new HashMap();
public static int key; //define whatever type you want
public static String value;
//Add elements
map.put("key","value");
map.put("key 1", "value 1");
//key collection
System.out.println(map.keySet());//Return Set
//Value collection
System.out.println(map.values()); //Return connection
//Query whether the key exists
System.out.println(map.containsKey("Key 1"));//Return Boolean type
//Delete the specified key and value by key
System.out.println(map.remove("Key 1"));//return object type
//Return the associated value according to the key, if it does not exist, return null
System.out.println(map.get("Key 1"));
//One-to-one correspondence between key values
System.out.println(map); //Conversion is required here
/****Traverse HashMap*****/
//I looked up some methods on the Internet but they didn't work, so I made one myself.
public String toString()
{
retunr "key"+key+"value"+value;
}
for(object s : map.values())
{
System.out.println(s);
}
//Method 2 gets the value
Set s = map.entrySet();
Iterator c =s.iterator();
HashMap a = new HashMap();
ArrayList al = new ArrayList();
a.put("name1", "abcdef"); // key is name, value is the string abcdef
al.add("name1");
a.put("name2","me");
al.add("name2");
a.put("name3","you");
al.add("name3");
a.put("name4","he");
al.add("name4");
for(int i=0;i<al.size();i++){
System.out.println(a.get(al.get(i)));
}
If you have any questions about java, C#, JSP, JS, DW, sql, and ASP, I will explain them in detail, but you need to have a keyboard. I broke the keyboard when typing this. If you have any projects, please contact QQ289172257 for price negotiation.