java.util(contd..)
Dated: 05-21-2001
StringTokenizer
Sample Code
import java.util.StringTokenizer;
class STDemo {
static String in = "Title=Java;" +
" Author= Mr. ABCD;"+
"Publisher=McGraw-Hill";
public static void main (String args[ ]) {
StringTokenizer st = new StringTokenizer (in, "=;");
//each character in the delimiters string is considered a valid delimiter.
while(st.hasMoreTokens()){
String key = st.nextToken();
String value = st.nextToken();
System.out.println (key + "\t" + val);
}
}
}
Output
Title Java
Author Mr. ABCD
Publisher McGraw-Hill
Date
Encapsulates the current date and time. Implements Comparable interface.
Date()
Date(long millis)
Method Summary |
|
|
after |
|
before |
clone |
|
|
compareTo |
|
|
|
|
|
getTime |
|
hashCode |
void |
setTime |
toString |
Sample Code
import java.util.*;
class DateDemo{
public static void main (String args[ ]){
Date date = new Date();
// to current date and time
System.out.println(date);
long msec = date.getTime();
System.out.println("Milliseconds since Jan. 1, 1970 GMT =" + msec);
}
}
Output:
Mon May 21 16:10:40 CST 2001
Milliseconds since Jan. 1, 1970 GMT = 1017192929029
Random
Is a generator of pseudorandom numbers. They are called pseudorandom numbers because they are simply distributed sequences.
Random ()
Random (long seed)
The first version creates a number generator that uses the current tiemas the starting, or seed value. If you use same seed to initialize two Random objects, you will extract the same random sequence.
Method Summary |
|
|
next |
|
nextBoolean |
|
nextBytes |
|
nextDouble |
|
nextFloat |
|
nextGaussian |
|
nextInt |
|
nextInt |
|
nextLong |
|
setSeed |
Piece of Code
Random r = new Random();
double val;
val = r.nextGaussian();