Comparable Interface
Class that implements the comparable interface. objects can be compared between different sizes.
The comparable interface has only one method.
Public int compareto (Object OBJ );
This method: returns 0 indicating this = OBJ
Returns a positive value indicating this> obj.
Returns a negative number, which indicates this> obj.
The class implementing the comparable interface uses the compareto method to determine the object sorting method.
You can use the sort () method to sort data.
Data structure selection:
Measurement criteria: Read efficiency and change Efficiency
Slow array read/write speed
Linked changed to fast-read and slow
Hash
Map Interface
The class that implements the map interface is used to store key-value pairs.
Implementation classes of the map interface include hashmap and treemap.
Key-value pairs stored in the map class are identified by keys. Therefore, key-value pairs cannot be repeated.
Object put (Object key, object value); // if the key already exists, the value of the original key is returned.
Object get (Object key );
Object remove (Object key );
Boolean containskey (Object key );
Boolean containsvalue (object value );
Int size ();
Boolean isempty ();
Void putall (MAP t );
Void clear ();
Use the hashcode () method for comparison.
Generic:
Enhance program readability and Stability
Define the object type in the collection at the same time when defining the set
Example:
Import java. util .*;
Public class testargswords {
Private Static final int one = 1;
Public static void main (string [] ARGs ){
Map <string, integer> M = new hashmap <string, integer> (); // generic
For (INT I = 0; I <args. length; I ++ ){
Int freq = (integer) M. Get (ARGs [I]) = NULL? 0 :( integer) M. Get (ARGs [I]);
M. Put (ARGs [I], freq + 1 );
}
System. Out. println (M. Size () + "distinct words detected :");
System. Out. println (m );
}
}
You can specify
You can also use iterator to specify