Extras din curs
Metode
addElement (Object) Adds the specified object as the last element of the vector.
capacity() Returns the current capacity of the vector.
clone() Returns a clone of the vector
contains(Object) Returns true if the specified object is a value of the collection.
copyInto(Objectst) Copies the elements of this vector into the specified array.
elementAt(int) Returns the element at the specified index.
elements() Returns an enumeration of the elements.
ensureCapacity(int) Ensures that the vector has at least the specified capacity.
firstElement() Returns the first element of the sequence.
indexOf(Object) Searches for the specified object, starting from the first position and returns an index to it.
indexOf(Object, int) Searches for the specified object, starting at the specified position and returns an index to it.
insertElementAt(Object, int) Inserts the specified object as an element at the specified index.
isEmpty() Returns true if the collection contains no values.
lastElement() Returns the last element of the sequence.
lastIndexOf(Object) Searches backwards for the specified object, starting from the last position and returns an index to it.
lastIndexOf(Object, int) Searches backwards for the specified object, starting from the specified position and returns an index to it.
removeAllElements() Removes all elements of the vector.
removeElement(Object) Removes the element from the vector.
removeElementAt(int) Deletes the element at the specified index.
setElementAt(Object, int) Sets the element at the specified index to be the specified object.
setSize(int) Sets the size of the vector.
size() Returns the number of elements in the vector.
toString() Converts the vector to a string.
trimToSize() Trims the vector's capacity down to size
Vectorii pot fi omogeni sau neomogeni. Exemplu:
Vector vectorNeomogen = new Vector();
vectorNeomogen.addElement(new Float(“3.141”));
vectorNeomogen.addElement(new Integer(20));
vectorNeomogen.addElement(new BitSet());
n STIVA
STACK (java.util.Stack)
Extinde clasa Vector si implementeaza o stiva LIFO.
Constructor
Stack ()
Metode
empty () Returns true if the stack is empty.
peek() Peeks at the top of the stack.
pop() Pops an item off the stack.
push(Object) Pushes an item onto the stack.
search(Object) Sees if an object is on the stack.
Alte clase :
Date
Random
StringTokenizer
BitSet
Dictionary
HashTable extends Dictionary
Properties extends HashTable
Exemple de folosire :
Date
• pentru afisarea zilei curente
Date d = new Date();
System.out.println("today = " + d);
• ziua corespunzatoare unei date
Date d = new Date(63, 0, 16); // January 16, 1963
System.out.println("Day of the week: " + d.getDay());
String Tokenizer
• descompunerea în unitati lexicale
String s = "this is a test";
StringTokenizer st = new StringTokenizer(s);
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
Va afisa :
this
is
a
test
Separatorii impliciti sunt atanar, dar pot fi definiti alti separatori în constructor :
Preview document
Conținut arhivă zip
- java.util.doc