My other sites |
New Summer Look :)
|
java.util.Vector |
java.util.Hashtable |
|
![]() |
|
The Vector class implements an expandable container for storing objects
Vector vect = new Vector();
vect.addElement("Hi");
vect.addElement(new Date());
vect.addElement("Bye");
System.out.println("Vector size: " + vect.size());
Object obj = vect.get(1);
if (obj instanceof String)
System.out.println("String: " + (String)obj);
else if(obj instanceof Date)
System.out.println("Date:" + (Date)obj);
|
![]() |
The Stack extends the Vector with stack functionality boolean empty() : Tests if this stack is empty Object peek() : Looks at the object at the top of this stack without removing it Object pop() : Removes the object at the top of this stack and returns that object as the value of this function void push(Object) : Pushes an item onto the top of this stack int search(Object): Returns where an object is on this stack |
![]() |
Stack stack = new Stack();
Object ob1 = new Object();
Object ob2 = new Object();
stack.push(ob1);
stack.push(ob2);
Object top = stack.peek(); // top is equal to ob2
Object tmp = stack.pop(); // tmp is also equal to ob2
Object tmp = stack.pop(); // tmp is now equal to ob1
if (stack.emtpy())
System.out.println("Stack is empty");
|
![]() |
An object that implements the Enumeration interface generates a series of elements, one at a time. Successive calls to the nextElement method return successive elements of the series Vector
vect = new Vector();
vect.addElement("Hi");
vect.addElement("Blipp");
vect.addElement("Bye");
for (Enumeration e=vect.elements();e.hasMoreElements();)
System.out.println(e.nextElement());
|
![]() |
This class implements a hashtable, which maps keys to values
Hashtable table = new Hashtable();
Object ob1 = new Object();
Object ob2 = new Object();
table.put("1",ob1);
table.put("2",ob2);
.
|
![]() |
An instance of this class is used to generate a stream
of pseudo random numbers Random rand = new Random(); rand.nextInt(); rand.nextFloat(); ... |
![]() |
- The StringTokenizer class allows a string to be broken
into Tokens - Operates using a delimiter character String data = "This is some data"; StringTokenizer st = new StringTokenizer(data); while (st.hasMoreTokens()) println(st.nextToken()); |