Hashtable-Hash Table class
Store data in the form of a hash table, and the data form is a key-value pair.
Features:
Fast search speed and slow Traversal
The key value cannot have null pointers or duplicate data.
Create
Hashtable <integer, string> ht = new hashtable <integer, string> ();
Add Value
Ht. Put (1, "Andy ");
Ht. Put (2, "Bill ");
Ht. Put (3, "Cindy ");
Ht. Put (4, "Dell ");
Ht. Put (5, "felex ");
Ht. Put (6, "Edinburg ");
Ht. Put (7, "green ");
Value
String STR = Ht. Get (1 );
System. Out. println (STR); // Andy
Traverse keys
Iterator it = Ht. keyset (). iterator ();
While (it. hasnext ()){
Integer key = (integer) it. Next ();
System. Out. println (key );
}
Traverse the value
Iterator it = Ht. Values (). iterator ();
While (it. hasnext ()){
String value = (string) it. Next ();
System. Out. println (value );
}
Number of hashtable records
Hashtable <integer, string> ht = new hashtable <integer, string> ();
Ht. Put (1, "Andy ");
Ht. Put (2, "Bill ");
Ht. Put (3, "Cindy ");
Ht. Put (4, "Dell ");
Ht. Put (5, "felex ");
Ht. Put (6, "Edinburg ");
Ht. Put (7, "green ");
Int I = HT. Size (); // 7
Delete Element
Hashtable <integer, string> ht = new hashtable <integer, string> ();
Ht. Put (1, "Andy ");
Ht. Put (2, "Bill ");
Ht. Put (3, "Cindy ");
Ht. Put (4, "Dell ");
Ht. Put (5, "felex ");
Ht. Put (6, "Edinburg ");
Ht. Put (7, "green ");
Ht. Remove (1 );
Ht. Remove (2 );
Ht. Remove (3 );
Ht. Remove (4 );
System. Out. println (HT. Size ());// 3
Iterator it = Ht. Values (). iterator ();
While (it. hasnext ()){
// Get value
String value = (string) it. Next ();
System. Out. println (value );
}
Truncates a string to a specified position in Java.
String Path = "http: /// localhost: 8080/client/index. JSP "; now I want to add the last slash ,'. 'previous parts (that is, 'index') are intercepted. How can we cut them?
Path. substring (path. lastindexof ("/") + 1, path. lastindexof ("."))