The Java map interface provides an object that maps a key to a value, HashMap TreeMap
| Method |
Function |
| Put (K key, V value) |
Adds a mapping relationship for the specified key, value to the collection |
| ContainsKey (Object key) |
Returns true if the mapping relationship that contains the specified key is checked |
| Containsvalue (Object value) |
This mapping maps one or more keys to the specified value values, returning True |
| Get (Object key) |
Returns the value of the specified key, otherwise returns null |
| KeySet () |
Returns the set set formed by all key objects |
| VALUES () |
Returns the collection collection of all value objects |
Algorithm title: Find the first occurrence of a character in a string.
1 PackageOffer ;2 3 ImportJava.util.HashMap;4 5 Public classFind_char {6 7 Public Static voidMain (string[] args) {8 //TODO auto-generated Method Stub9Get ("Abcdefacbwqewwwwewqew");Ten } One A Public Static voidget (String s) { -Hashmap<string,integer> map=NewHashmap<string,integer>(); - Char[] cs=S.tochararray (); the for(inti=0;i<cs.length;i++){ - if(Map.containskey (cs[i]+ "")) {//to see if a mapping relationship with the specified key value is included -Map.put (cs[i]+ "", (Map.get (cs[i]+ "") +1));//The Get function returns the value corresponding to the specified key key, otherwise returns null - } + Else{ -Map.put (cs[i]+ "", 1); + A } at } - for(intj=0;j<cs.length;j++){ - if(Map.get (cs[j]+ "") ==1) {//the Get () returns the value of the specified key value key; - System.out.println (Cs[j]); - Break; - in } - } to } +}
Finds the first occurrence of a character in a string