1,LinkedList
Achieve two-way circular list
ArrayList, LinkedList and Vector difference of?
ArrayList and Vector are using an array of storage, using two-way circular linked list LinkedList implement
the query ArrayList and Vector fast, fast data additions and deletions LinkedList
ArrayList is not thread-safe, Vector thread-safe (JDK1.5 provides an API for concurrent)
2, Set Interface:
Can not be repeated, does not guarantee the order
HashSet: determining whether to repeat elements, depending on the elements and hashCode equlas
TreeSet: guarantee the order, based on: 1, element 2 implements Comparable interface, passing the constructor Comparator
3, Map interface to: store the key value of
the HashMap: depending on whether the duplicate key and key equlas the hashCode
PUT (K, V)
V GET (K)
Collection values ()
the Set keySet ()
the Set <of Map.Entry <K, V> > entrySet ()
Hashtable
Properties
4, Collections, provides a method of operation for the collection of a number of
Task:
1, there is now a map set as follows:
the Map <Integer, String> = new new map the HashMap <Integer, String> ();
map.put (1, "Joe Smith");
map.put (2, "John Doe ");
map.put (. 3," Wang Mazi ");
map.put (. 4," Laotan ");
claim:
1. through the collection, and the number corresponding to the print name.
2. To insert a map set name is coded as information 5 "snail Institute" in
3. Remove the information in the map number 4
4. map set number 3 of the name information changed to "Wang Wu "
public class job { public static void main(String[] args){ Map<Integer,String> map=new HashMap<>(); map.put(1, "张三"); map.put(2, "李四"); map.put(3, "王麻子"); map.put(4, "老谭"); //1, Set<Map.Entry<Integer, String>> set=map.entrySet(); for (Entry<Integer, String> entry : set) { System.out.println(entry); } //2, map.put(5, "woniu"); //3, map.remove(4); //4 map.put(3, "王五"); for (Entry<Integer, String> entry : set) { System.out.println(entry); } }}
2, randomly generated integer between 1-10 1000, which count the number of occurring
public class Job2 { public static void main(String[] args) { // TODO Auto-generated method stub Map<Integer,Integer> map=new HashMap<>(); int[] z=new int[10]; for(int i=0;i<10;i++){ z[i]=0; } for(int i=0;i<1000;i++){ int x=(int)(Math.random()*10+1); map.put(x,z[x-1]++); } Set<Entry<Integer, Integer>> set=map.entrySet(); for (Entry<Integer, Integer> entry : set) { System.out.println(entry); } } }
3, the user's keyboard input from a number of names, the number of statistics by last name
public class job3 { public static void main(String[] args) { // TODO Auto-generated method stub Map<String,Integer> map=new HashMap<>(); Set<String> keys = map.keySet(); Scanner scanner = new Scanner(System.in); while (true) { System.out.print("请输入姓名"); String name=scanner.next(); String x=name.substring(0, 1); if(!(keys.contains(x))){ map.put(x, 1); }else{ map.put(x, map.get(x)+1); } Set<Entry<String, Integer>> set=map.entrySet(); for (Entry<String, Integer> entry : set) { System.out.println(entry); } } } }
4, is defined as a generic List collection of type String, the collection of statistics for each character (note, not a string) the number of occurrences. For example: the collection have "abc", "bcd" two elements, the final output of the program is: "a = 1, b = 2, c = 2, d = 1"
public class Job4 { public static void main(String[] args) { // TODO Auto-generated method stub List<String> list=new ArrayList<>(); Map<String,Integer> map=new HashMap<>(); Set<String> keys = map.keySet(); list.add("abc"); list.add("ca"); for(int i=0;i<list.size();i++){ int a=0; int b=1; for(int j=0;j<list.get(i).length();j++){ String string=list.get(i).substring(a++, b++); System.out.println(string); if(!(keys.contains(string))){ map.put(string, 1); }else{ map.put(string, map.get(string)+1); } } } Set<Entry<String, Integer>> set=map.entrySet(); for (Entry<String, Integer> entry : set) { System.out.println(entry); } } }
5,
1 metro station number and the name of the station correspondence is as follows:
1 = Tianfu Square
2 = Provincial Stadium
3 = Nijia bridge
4 = South Railway Station
5 = Incubator
6 = Century City
7 = Tianfu Third Street
8 = Tianfu five streets
// ....
the above correspondence relationship storing data into map set, Key: represents the station number, value: indicates the name of the station, and traverse the print (print may not order):
2. calculate the fare rules:
total trip 3 station (comprising three stations) charge 3 million,
more than 3 points but less than 5 points (comprising 5 points) are charged $ 4,
5 or more stations, on the basis of $ 4 on each over station increase of 2 million,
10 yuan cap;
3. print format (requires keyboard input on the station and arrival station to determine if the station is not prompted to re-enter, until there is station name):
Note: 2 minutes per station
enter the station:
you enter on the station: Science and Technology Museum does not exist, please re-enter the station:
Tianfu Square
enter arrival station:
arrival station you entered: Science and Technology Museum does not exist, please re-enter your arrival station:
incubator
from Tianfu Square to the incubator after a total of 4 station charges $ 4, about 8 minutes