Enumeration Enumeration
rarely use
Methods: boolean hasMoreElements () Tests if this enumeration contains more elements.
Object nextElement () element if this enumeration object has at least one available, the next element of this enumeration is returned.
Enumeration<String> days;
Vector<String> dayNames = new Vector<String>();
dayNames.add("Sunday");
dayNames.add("Monday");
dayNames.add("Tuesday");
dayNames.add("Wednesday");
dayNames.add("Thursday");
dayNames.add("Friday");
dayNames.add("Saturday");
days = dayNames.elements();
while (days.hasMoreElements()){ System.out.println(days.nextElement()); }
Java collection interfaces
Collection interface, the most basic set of interfaces, generally do not use
List Interface
Set interface elements unique disorder
The only ordered element SortedSet
Map key target
Dictionary Directionary kind of outdated, you can implement the interface map to get the ability to store key-value pairs
Enumeration elements () Returns enum values in this dictionary.
Object get (Object key) Returns the value of the key is mapped in this dictionary.
boolean isEmpty () test from this dictionary is mapped to the key value does not exist.
Enumeration keys () Returns the enumeration of the keys in this dictionary.
Object put (Object key, Object value ) Maps the specified key in this dictionary specified value.
Object remove (Object key) from the dictionary is removed key (and its corresponding value).
int size () Returns a dictionary entry (a different key) number.
Iterator
List <String> list = new ArrayList <string> (); use the list created in this manner, the advantages of variable length
list.add("abc")
Iterator<String> ite = list.iterator();
while (ite.hasNext ()) {ite.next ();} in a manner iterator value
Map Types
Map<String, String> map = new HashMap<String, String>();
Map . PUT ( " . 1 " , " VALUE1 " ) ; padding value
map.get ( "1"); the corresponding key value takes
map.keySet () to return all keys
map.values()
Console input (similar to the python's input, but more difficult to achieve) must catch the next try
{the try
the BufferedReader BufferedReader the BufferedReader new new = (
new new the InputStreamReader (the System.in));
String BufferedReader.readLine K = ();
System.out.println (K);
System.out.println (System.in.toString ());
System.out.println ( "Hello");
} the catch (IOException E) {
System.out.println ( "");
}
the second embodiment of console input
SC = new new Scanner Scanner (the System.in);
System.out.println (sc.nextLine ()); relatively simple to achieve
In a string: String = sc.next STR ();
Read an entire row of data: String = lineString sc.nextLine ();
Reading a Boolean value: Boolean = boolenaNumber sc.nextBoolean ();
Read a byte of data: byte byteNumbe sc.nextByte = ();
A short integer data read in: Short shortNumber sc.nextShort = ();
Read an integer: int = intNumber sc.nextInt ();
Reading a long data: Long longNumber sc.nextLong = ();
Reading a single precision floating point: a float floatNumber sc.nextFloat = ();
Reads a double precision floating point: Double doubleNumber sc.nextDouble = ();
Code computation time calculation
long startTime = System.nanoTime(); // … the code being measured … long estimatedTime = System.nanoTime() - startTime;
String formatted output
String l = "ad%s%d";
String m = String.format(l,"3",5);