The java.util package defines a number of useful classes, primarily collections classes that are useful for working with groups of objects. This package should not be considered merely a utility package that is separate from the rest of the language; in fact, Java depends directly on several of the classes in this package. Figure 23-1 shows the collection classes of this package, while Figure 23-2 shows the other classes.
The most important classes in java.util are the collections classes. Prior to Java 1.2, these were Vector, a growable list of objects, and Hashtable, a mapping between arbitrary key and value objects. Java 1.2 adds an entire collections framework consisting of the Collection, Map, Set, List, SortedMap, and SortedSet interfaces and the classes that implement them. Other important classes and interfaces of the collections framework are Comparator, Collections, Arrays, Iterator, and ListIterator.
The other classes of the package are also useful. Date, Calendar, and TimeZone work with dates and times. ResourceBundle and its subclasses represent a bundle of localized resources that are read in by an internationalized program at runtime. BitSet implements an arbitrary-size array of bits. Random generates and returns pseudo-random numbers in a variety of forms. StringTokenizer parses a string into tokens. Finally, in Java 1.3, Timer and TimerTask provide a powerful API for scheduling code to be run by a background thread, once or repetitively, at a specified time in the future.
AbstractCollection | Java 1.2 | |
|
||
java.util | collection |
This abstract class is a partial implementation of Collection that makes it easy to define custom Collection implementations. To create an unmodifiable collection, simply override size() and iterator(). The Iterator object returned by iterator() has to support only the hasNext() and next() methods. To define a modifiable collection, you must additionally override the add() method of AbstractCollection and make sure the Iterator returned by iterator() supports the remove() method. Some subclasses may choose to override other methods to tune performance. In addition, it is conventional that all subclasses provide two constructors: one that takes no arguments and one that accepts a Collection argument that specifies the initial contents of the collection.
Note that if you subclass AbstractCollection directly, you are implementing a bag--an unordered collection that allows duplicate elements. If your add() method rejects duplicate elements, you should subclass AbstractSet instead. See also AbstractList.
public abstract class AbstractCollection implements Collection { | ||
// | Protected Constructors | |
protected AbstractCollection (); | ||
// | Methods Implementing Collection | |
public boolean add (Object o); | ||
public boolean addAll (Collection c); | ||
public void clear (); | ||
public boolean contains (Object o); | ||
public boolean containsAll (Collection c); | ||
public boolean isEmpty (); | ||
public abstract Iterator iterator (); | ||
public boolean remove (Object o); | ||
public boolean removeAll (Collection c); | ||
public boolean retainAll (Collection c); | ||
public abstract int size (); | ||
public Object[ ] toArray (); | ||
public Object[ ] toArray (Object[ ] a); | ||
// | Public Methods Overriding Object | |
public String toString (); | ||
} |
Hierarchy: Object-->AbstractCollection(Collection)
Subclasses: AbstractList, AbstractSet
AbstractList | Java 1.2 | |
|
||
java.util | collection |
This abstract class is a partial implementation of the List interface that makes it easy to define custom List implementations based on random-access list elements (such as objects stored in an array). If you want to base a List implementation on a sequential-access data model (such as a linked list), subclass AbstractSequentialList instead.
To create an unmodifiable List, simply subclass AbstractList and override the (inherited) size() and get() methods. To create a modifiable list, you must also override set() and, optionally, add() and remove(). These three methods are optional, so unless you override them, they simply throw an UnsupportedOperationException. All other methods of the List interface are implemented in terms of size(), get(), set(), add(), and remove(). In some cases, you may want to override these other methods to improve performance. By convention, all List implementations should define two constructors: one that accepts no arguments and another that accepts a Collection of initial elements for the list.
public abstract class AbstractList extends AbstractCollection implements java.util.List { | ||
// | Protected Constructors | |
protected AbstractList (); | ||
// | Methods Implementing List | |
public boolean add (Object o); | ||
public void add (int index, Object element); | ||
public boolean addAll (int index, Collection c); | ||
public void clear (); | ||
public boolean equals (Object o); | ||
public abstract Object get (int index); | ||
public int hashCode (); | ||
public int indexOf (Object o); | ||
public Iterator iterator (); | ||
public int lastIndexOf (Object o); | ||
public ListIterator listIterator (); | ||
public ListIterator listIterator (int index); | ||
public Object remove (int index); | ||
public Object set (int index, Object element); | ||
public java.util.List subList (int fromIndex, int toIndex); | ||
// | Protected Instance Methods | |
protected void removeRange (int fromIndex, int toIndex); | ||
// | Protected Instance Fields | |
protected transient int modCount ; | ||
} |
Hierarchy: Object-->AbstractCollection(Collection)-->AbstractList(java.util.List(Collection))
Subclasses: AbstractSequentialList, ArrayList, Vector
AbstractMap | Java 1.2 | |
|
||
java.util | collection |
This abstract class is a partial implementation of the Map interface that makes it easy to define simple custom Map implementations. To define an unmodifiable map, subclass AbstractMap and override the entrySet() method so that it returns a set of Map.Entry objects. (Note that you must also implement Map.Entry, of course.) The returned set should not support add() or remove(), and its iterator should not support remove(). In order to define a modifiable Map, you must additionally override the put() method and provide support for the remove() method of the iterator returned by entrySet().iterator(). In addition, it is conventional that all Map implementations define two constructors: one that accepts no arguments and another that accepts a Map of initial mappings.
AbstractMap defines all Map methods in terms of its entrySet() and put() methods and the remove() method of the entry set iterator. Note, however, that the implementation is based on a linear search of the Set returned by entrySet() and is not efficient when the Map contains more than a handful of entries. Some subclasses may want to override additional AbstractMap methods to improve performance. HashMap and TreeMap use different algorithms are are substantially more efficient.
public abstract class AbstractMap implements Map { | ||
// | Protected Constructors | |
protected AbstractMap (); | ||
// | Methods Implementing Map | |
public void clear (); | ||
public boolean containsKey (Object key); | ||
public boolean containsValue (Object value); | ||
public abstract Set entrySet (); | ||
public boolean equals (Object o); | ||
public Object get (Object key); | ||
public int hashCode (); | ||
public boolean isEmpty (); | ||
public Set keySet (); | ||
public Object put (Object key, Object value); | ||
public void putAll (Map t); | ||
public Object remove (Object key); | ||
public int size (); | ||
public Collection values (); | ||
// | Public Methods Overriding Object | |
public String toString (); | ||
} |
Hierarchy: Object-->AbstractMap(Map)
Subclasses: HashMap, TreeMap, WeakHashMap
AbstractSequentialList | Java 1.2 | |
|
||
java.util | collection |
This abstract class is a partial implementation of the List interface that makes it easy to define List implementations based on a sequential-access data model, as is the case with the LinkedList subclass. To implement a List based on an array or other random-access model, subclass AbstractList instead.
To implement an unmodifiable list, subclass this class and override the size() and listIterator() methods. listIterator() must return a ListIterator that defines the hasNext(), hasPrevious(), next(), previous(), and index() methods. If you want to allow the list to be modified, the ListIterator should also support the set() method and, optionally, the add() and remove() methods. AbstractSequentialList implements all other List methods in terms of these methods. Some subclasses may want to override additional methods to improve performance. In addition, it is conventional that all List implementations define two constructors: one that accepts no arguments and another that accepts a Collection of initial elements for the list.
public abstract class AbstractSequentialList extends AbstractList { | ||
// | Protected Constructors | |
protected AbstractSequentialList (); | ||
// | Public Methods Overriding AbstractList | |
public void add (int index, Object element); | ||
public boolean addAll (int index, Collection c); | ||
public Object get (int index); | ||
public Iterator iterator (); | ||
public abstract ListIterator listIterator (int index); | ||
public Object remove (int index); | ||
public Object set (int index, Object element); | ||
} |
Hierarchy: Object-->AbstractCollection(Collection)-->AbstractList(java.util.List(Collection))-->AbstractSequentialList
Subclasses: LinkedList
AbstractSet | Java 1.2 | |
|
||
java.util | collection |
This abstract class is a partial implementation of the Set interface that makes it easy to create custom Set implementations. Since Set defines the same methods as Collection, you can subclass AbstractSet exactly as you would subclass AbstractCollection. See AbstractCollection for details. Note, however, that when subclassing AbstractSet, you should be sure that your add() method and your constructors do not allow duplicate elements to be added to the set. See also AbstractList.
public abstract class AbstractSet extends AbstractCollection implements Set { | ||
// | Protected Constructors | |
protected AbstractSet (); | ||
// | Methods Implementing Set | |
public boolean equals (Object o); | ||
public int hashCode (); | ||
} |
Hierarchy: Object-->AbstractCollection(Collection)-->AbstractSet(Set(Collection))
Subclasses: HashSet, TreeSet
ArrayList | Java 1.2 | |
|
||
java.util | cloneable serializable collection |
This class is a List implementation based on an array (that is recreated as necessary as the list grows or shrinks). ArrayList implements all optional List and Collection methods and allows list elements of any type (including null). Because ArrayList is based on an array, the get() and set() methods are very efficient. (This is not the case for the LinkedList implementation, for example.) ArrayList is a general-purpose implementation of List and is quite commonly used. ArrayList is very much like the Vector class, except that its methods are not synchronized. If you are using an ArrayList in a multithreaded environment, you should explicitly synchronize any modifications to the list, or wrap the list with Collections.synchronizedList(). See List and Collection for details on the methods of ArrayList. See also LinkedList.
An ArrayList has a capacity, which is the number of elements in the internal array that contains the elements of the list. When the number of elements exceeds the capacity, a new array, with a larger capacity, must be created. In addition to the List and Collection methods, ArrayList defines a couple of methods that help you manage this capacity. If you know in advance how many elements an ArrayList will contain, you can call ensureCapacity(), which can increase efficiency by avoiding incremental reallocation of the internal array. You can also pass an initial capacity value to the ArrayList() constructor. Finally, if an ArrayList has reached its final size and will not change in the future, you can call trimToSize() to reallocate the internal array with a capacity that matches the list size exactly. When the ArrayList will have a long lifetime, this can be a useful technique to reduce memory usage.
public class ArrayList extends AbstractList implements Cloneable, java.util.ListSerializable { | ||
// | Public Constructors | |
public ArrayList (); | ||
public ArrayList (int initialCapacity); | ||
public ArrayList (Collection c); | ||
// | Public Instance Methods | |
public void ensureCapacity (int minCapacity); | ||
public void trimToSize (); | ||
// | Methods Implementing List | |
public boolean add (Object o); | ||
public void add (int index, Object element); | ||
public boolean addAll (Collection c); | ||
public boolean addAll (int index, Collection c); | ||
public void clear (); | ||
public boolean contains (Object elem); | ||
public Object get (int index); | ||
public int indexOf (Object elem); | ||
public boolean isEmpty (); | default:true | |
public int lastIndexOf (Object elem); | ||
public Object remove (int index); | ||
public Object set (int index, Object element); | ||
public int size (); | ||
public Object[ ] toArray (); | ||
public Object[ ] toArray (Object[ ] a); | ||
// | Protected Methods Overriding AbstractList | |
protected void removeRange (int fromIndex, int toIndex); | ||
// | Public Methods Overriding Object | |
public Object clone (); | ||
} |
Hierarchy: Object-->AbstractCollection(Collection)-->AbstractList(java.util.List(Collection))-->ArrayList(Cloneable,java.util.List(Collection),Serializable)
Type Of: java.awt.dnd.DragGestureRecognizer.events, java.beans.beancontext.BeanContextServicesSupport.bcsListeners, java.beans.beancontext.BeanContextSupport.bcmListeners
Arrays | Java 1.2 | |
|
||
java.util |
This class defines static methods for sorting, searching, and performing other useful operations on arrays. It also defines the asList() method, which returns a List wrapper around a specified array of objects. Any changes made to the List are also made to the underlying array. This is a powerful method that allows any array of objects to be manipulated in any of the ways a List can be manipulated. It provides a link between arrays and the Java collections framework.
The various sort() methods sort an array (or a specified portion of an array) in place. Variants of the method are defined for arrays of each primitive type and for arrays of Object. For arrays of primitive types, the sorting is done according to the natural ordering of the type. For arrays of objects, the sorting is done according to the specified Comparator, or, if the array contains only java.lang.Comparable objects, according to the ordering defined by that interface. When sorting an array of objects, a stable sorting algorithm is used so that the relative ordering of equal objects is not disturbed. (This allows repeated sorts to order objects by key and subkey, for example.)
The binarySearch() methods perform an efficient search (in logarithmic time) of a sorted array for a specified value. If a match is found in the array, binarySearch() returns the index of the match. If no match is found, the method returns a negative number. For a negative return value r, the index -(r+1) specifies the array index at which the specified value can be inserted to maintain the sorted order of the array. When the array to be searched is an array of objects, the elements of the array must all implement java.lang.Comparable, or you must provide a Comparator object to compare them.
The equals() methods test whether two arrays are equal. Two arrays of primitive type are equal if they contain the same number of elements and if corresponding pairs of elements are equal according to the == operator. Two arrays of objects are equal if they contain the same number of elements and if corresponding pairs of elements are equal according to the equals() method defined by those objects. The fill() methods fill an array or a specified range of an array with the specified value.
public class Arrays { | ||
// | No Constructor | |
// | Public Class Methods | |
public static java.util.List asList (Object[ ] a); | ||
public static int binarySearch (short[ ] a, short key); | ||
public static int binarySearch (Object[ ] a, Object key); | ||
public static int binarySearch (long[ ] a, long key); | ||
public static int binarySearch (int[ ] a, int key); | ||
public static int binarySearch (double[ ] a, double key); | ||
public static int binarySearch (byte[ ] a, byte key); | ||
public static int binarySearch (char[ ] a, char key); | ||
public static int binarySearch (float[ ] a, float key); | ||
public static int binarySearch (Object[ ] a, Object key, Comparator c); | ||
public static boolean equals (boolean[ ] a, boolean[ ] a2); | ||
public static boolean equals (byte[ ] a, byte[ ] a2); | ||
public static boolean equals (float[ ] a, float[ ] a2); | ||
public static boolean equals (double[ ] a, double[ ] a2); | ||
public static boolean equals (int[ ] a, int[ ] a2); | ||
public static boolean equals (long[ ] a, long[ ] a2); | ||
public static boolean equals (char[ ] a, char[ ] a2); | ||
public static boolean equals (short[ ] a, short[ ] a2); | ||
public static boolean equals (Object[ ] a, Object[ ] a2); | ||
public static void fill (double[ ] a, double val); | ||
public static void fill (char[ ] a, char val); | ||
public static void fill (short[ ] a, short val); | ||
public static void fill (Object[ ] a, Object val); | ||
public static void fill (float[ ] a, float val); | ||
public static void fill (byte[ ] a, byte val); | ||
public static void fill (int[ ] a, int val); | ||
public static void fill (long[ ] a, long val); | ||
public static void fill (boolean[ ] a, boolean val); | ||
public static void fill (Object[ ] a, int fromIndex, int toIndex, Object val); | ||
public static void fill (boolean[ ] a, int fromIndex, int toIndex, boolean val); | ||
public static void fill (byte[ ] a, int fromIndex, int toIndex, byte val); | ||
public static void fill (float[ ] a, int fromIndex, int toIndex, float val); | ||
public static void fill (short[ ] a, int fromIndex, int toIndex, short val); | ||
public static void fill (int[ ] a, int fromIndex, int toIndex, int val); | ||
public static void fill (long[ ] a, int fromIndex, int toIndex, long val); | ||
public static void fill (double[ ] a, int fromIndex, int toIndex, double val); | ||
public static void fill (char[ ] a, int fromIndex, int toIndex, char val); | ||
public static void sort (char[ ] a); | ||
public static void sort (short[ ] a); | ||
public static void sort (int[ ] a); | ||
public static void sort (byte[ ] a); | ||
public static void sort (double[ ] a); | ||
public static void sort (float[ ] a); | ||
public static void sort (long[ ] a); | ||
public static void sort (Object[ ] a); | ||
public static void sort (Object[ ] a, Comparator c); | ||
public static void sort (short[ ] a, int fromIndex, int toIndex); | ||
public static void sort (Object[ ] a, int fromIndex, int toIndex); | ||
public static void sort (byte[ ] a, int fromIndex, int toIndex); | ||
public static void sort (char[ ] a, int fromIndex, int toIndex); | ||
public static void sort (float[ ] a, int fromIndex, int toIndex); | ||
public static void sort (double[ ] a, int fromIndex, int toIndex); | ||
public static void sort (int[ ] a, int fromIndex, int toIndex); | ||
public static void sort (long[ ] a, int fromIndex, int toIndex); | ||
public static void sort (Object[ ] a, int fromIndex, int toIndex, Comparator c); | ||
} |
BitSet | Java 1.0 | |
|
||
java.util | cloneable serializable PJ1.1 |
This class defines an arbitrarily large set of bits. Instance methods allow you to set, clear, and query individual bits in the set. You can also perform bitwise boolean arithmetic on the bits in BitSet objects. This class can be used as an extremely compact array of boolean values, although reading and writing those values is slower than normal array access.
public class BitSet implements Cloneable, Serializable { | ||
// | Public Constructors | |
public BitSet (); | ||
public BitSet (int nbits); | ||
// | Public Instance Methods | |
public void and (BitSet set); | ||
1.2 | public void andNot (BitSet set); | |
public void clear (int bitIndex); | ||
public boolean get (int bitIndex); | ||
1.2 | public int length (); | |
public void or (BitSet set); | ||
public void set (int bitIndex); | ||
public int size (); | ||
public void xor (BitSet set); | ||
// | Public Methods Overriding Object | |
public Object clone (); | ||
public boolean equals (Object obj); | ||
public int hashCode (); | ||
public String toString (); | ||
} |
Hierarchy: Object-->BitSet(Cloneable,Serializable)
Passed To: BitSet.{and(), andNot(), or(), xor()}, javax.swing.text.html.parser.DTD.defineElement()
Type Of: javax.swing.text.html.parser.Element.{exclusions, inclusions}
Calendar | Java 1.1 | |
|
||
java.util | cloneable serializable PJ1.1 |
This abstract class defines methods that perform date and time arithmetic. It also includes methods that convert dates and times to and from the machine-usable millisecond format used by the Date class and units such as minutes, hours, days, weeks, months, and years that are more useful to humans. As an abstract class, Calendar cannot be directly instantiated. Instead, it provides static getInstance() methods that return instances of a Calendar subclass suitable for use in a specified or default locale with a specified or default time zone. See also Date, DateFormat, and TimeZone.
Calendar defines a number of useful constants. Some of these are values that represent days of the week and months of the year. Other constants, such as HOUR and DAY_OF_WEEK, represent various fields of date and time information. These field constants are passed to a number of Calendar methods, such as get() and set(), in order to indicate what particular date or time field is desired.
setTime() and the various set() methods set the date represented by a Calendar object. The add() method adds (or subtracts) values to a calendar field, incrementing the next larger field when the field being set rolls over. roll() does the same, without modifying anything but the specified field. before() and after() compare two Calendar objects. Many of the methods of the Calendar class are replacements for methods of Date that have been deprecated as of Java 1.1. While the Calendar class converts a time value to its various hour, day, month, and other fields, it is not intended to present those fields in a form suitable for display to the end user. That function is performed by the java.text.DateFormat class, which handles internationalization issues.
public abstract class Calendar implements Cloneable, Serializable { | ||
// | Protected Constructors | |
protected Calendar (); | ||
protected Calendar (TimeZone zone, Locale aLocale); | ||
// | Public Constants | |
public static final int AM ; | =0 | |
public static final int AM_PM ; | =9 | |
public static final int APRIL ; | =3 | |
public static final int AUGUST ; | =7 | |
public static final int DATE ; | =5 | |
public static final int DAY_OF_MONTH ; | =5 | |
public static final int DAY_OF_WEEK ; | =7 | |
public static final int DAY_OF_WEEK_IN_MONTH ; | =8 | |
public static final int DAY_OF_YEAR ; | =6 | |
public static final int DECEMBER ; | =11 | |
public static final int DST_OFFSET ; | =16 | |
public static final int ERA ; | =0 | |
public static final int FEBRUARY ; | =1 | |
public static final int FIELD_COUNT ; | =17 | |
public static final int FRIDAY ; | =6 | |
public static final int HOUR ; | =10 | |
public static final int HOUR_OF_DAY ; | =11 | |
public static final int JANUARY ; | =0 | |
public static final int JULY ; | =6 | |
public static final int JUNE ; | =5 | |
public static final int MARCH ; | =2 | |
public static final int MAY ; | =4 | |
public static final int MILLISECOND ; | =14 | |
public static final int MINUTE ; | =12 | |
public static final int MONDAY ; | =2 | |
public static final int MONTH ; | =2 | |
public static final int NOVEMBER ; | =10 | |
public static final int OCTOBER ; | =9 | |
public static final int PM ; | =1 | |
public static final int SATURDAY ; | =7 | |
public static final int SECOND ; | =13 | |
public static final int SEPTEMBER ; | =8 | |
public static final int SUNDAY ; | =1 | |
public static final int THURSDAY ; | =5 | |
public static final int TUESDAY ; | =3 | |
public static final int UNDECIMBER ; | =12 | |
public static final int WEDNESDAY ; | =4 | |
public static final int WEEK_OF_MONTH ; | =4 | |
public static final int WEEK_OF_YEAR ; | =3 | |
public static final int YEAR ; | =1 | |
public static final int ZONE_OFFSET ; | =15 | |
// | Public Class Methods | |
public static Locale[ ] getAvailableLocales (); | synchronized | |
public static Calendar getInstance (); | synchronized | |
public static Calendar getInstance (Locale aLocale); | synchronized | |
public static Calendar getInstance (TimeZone zone); | synchronized | |
public static Calendar getInstance (TimeZone zone, Locale aLocale); | synchronized | |
// | Property Accessor Methods (by property name) | |
public int getFirstDayOfWeek (); | ||
public void setFirstDayOfWeek (int value); | ||
public boolean isLenient (); | ||
public void setLenient (boolean lenient); | ||
public int getMinimalDaysInFirstWeek (); | ||
public void setMinimalDaysInFirstWeek (int value); | ||
public final java.util.Date getTime (); | ||
public final void setTime (java.util.Date date); | ||
public TimeZone getTimeZone (); | ||
public void setTimeZone (TimeZone value); | ||
// | Public Instance Methods | |
public abstract void add (int field, int amount); | ||
public boolean after (Object when); | ||
public boolean before (Object when); | ||
public final void clear (); | ||
public final void clear (int field); | ||
public final int get (int field); | ||
1.2 | public int getActualMaximum (int field); | |
1.2 | public int getActualMinimum (int field); | |
public abstract int getGreatestMinimum (int field); | ||
public abstract int getLeastMaximum (int field); | ||
public abstract int getMaximum (int field); | ||
public abstract int getMinimum (int field); | ||
public final boolean isSet (int field); | ||
1.2 | public void roll (int field, int amount); | |
public abstract void roll (int field, boolean up); | ||
public final void set (int field, int value); | ||
public final void set (int year, int month, int date); | ||
public final void set (int year, int month, int date, int hour, int minute); | ||
public final void set (int year, int month, int date, int hour, int minute, int second); | ||
// | Public Methods Overriding Object | |
public Object clone (); | ||
public boolean equals (Object obj); | ||
1.2 | public int hashCode (); | |
public String toString (); | ||
// | Protected Instance Methods | |
protected void complete (); | ||
protected abstract void computeFields (); | ||
protected abstract void computeTime (); | ||
protected long getTimeInMillis (); | ||
protected final int internalGet (int field); | ||
protected void setTimeInMillis (long millis); | ||
// | Protected Instance Fields | |
protected boolean areFieldsSet ; | ||
protected int[ ] fields ; | ||
protected boolean[ ] isSet ; | ||
protected boolean isTimeSet ; | ||
protected long time ; | ||
} |
Hierarchy: Object-->Calendar(Cloneable,Serializable)
Subclasses: GregorianCalendar
Passed To: Too many methods to list.
Returned By: java.text.DateFormat.getCalendar(), Calendar.getInstance()
Type Of: java.text.DateFormat.calendar
Collection | Java 1.2 | |
|
||
java.util | collection |
This interface represents a group, or collection, of objects. The objects may or may not be ordered, and the collection may or may not contain duplicate objects. Collection is not often implemented directly. Instead, most collection classes implement one of the more specific subinterfaces: Set, an unordered collection that does not allow duplicates, or List, an ordered collection that does allow duplicates.
The Collection type provides a general way to refer to any set, list, or other collection of objects; it defines generic methods that work with any collection. contains() and containsAll() test whether the Collection contains a specified object or all the objects in a given collection. isEmpty() returns true if the Collection has no elements, or false otherwise. size() returns the number of elements in the Collection. iterator() returns an Iterator object that allows you to iterate through the objects in the collection. toArray() returns the objects in the Collection in a new array of type Object. Another version of toArray() takes an array as an argument and stores all elements of the Collection (which must all be compatible with the array) into that array. If the array is not big enough, the method allocates a new, larger array of the same type. If the array is too big, the method stores null into the first empty element of the array. This version of toArray() returns the array that was passed in or the new array, if one was allocated.
The previous methods all query or extract the contents of a collection. The Collection interface also defines methods for modifying the contents of the collection. add() and addAll() add an object or a collection of objects to a Collection. remove() and removeAll() remove an object or collection. retainAll() is a variant that removes all objects except those in a specified Collection. clear() removes all objects from the collection. All these modification methods except clear() return true if the collection was modified as a result of the call. An interface cannot specify constructors, but it is conventional that all implementations of Collection provide at least two standard constructors: one that takes no arguments and creates an empty collection, and a copy constructor that accepts a Collection object that specifies the initial contents of the new Collection.
Implementations of Collection and its subinterfaces are not required to support all operations defined by the Collection interface. All modification methods listed above are optional; an implementation (such as an immutable Set implementation) that does not support them simply throws java.lang.UnsupportedOperationException for these methods. Furthermore, implementations are free to impose restrictions on the types of objects that can be members of a collection. Some implementations might require elements to be of a particular type, for example, and others might not allow null as an element.
See also Set, List, Map, and Collections.
public interface Collection { | ||
// | Public Instance Methods | |
public abstract boolean add (Object o); | ||
public abstract boolean addAll (Collection c); | ||
public abstract void clear (); | ||
public abstract boolean contains (Object o); | ||
public abstract boolean containsAll (Collection c); | ||
public abstract boolean equals (Object o); | ||
public abstract int hashCode (); | ||
public abstract boolean isEmpty (); | ||
public abstract Iterator iterator (); | ||
public abstract boolean remove (Object o); | ||
public abstract boolean removeAll (Collection c); | ||
public abstract boolean retainAll (Collection c); | ||
public abstract int size (); | ||
public abstract Object[ ] toArray (); | ||
public abstract Object[ ] toArray (Object[ ] a); | ||
} |
Implementations: java.beans.beancontext.BeanContext, AbstractCollection, java.util.List, Set
Passed To: Too many methods to list.
Returned By: java.awt.RenderingHints.values(), java.security.Provider.values(), java.security.cert.CertificateFactory.{generateCertificates(), generateCRLs()}, java.security.cert.CertificateFactorySpi.{engineGenerateCertificates(), engineGenerateCRLs()}, AbstractMap.values(), Collections.{synchronizedCollection(), unmodifiableCollection()}, HashMap.values(), Hashtable.values(), Map.values(), TreeMap.values(), java.util.jar.Attributes.values()
Type Of: java.beans.beancontext.BeanContextMembershipEvent.children
Collections | Java 1.2 | |
|
||
java.util |
This class defines static methods and constants that are useful for working with collections and maps. One of the most commonly used methods is sort(), which sorts a List in place (the list cannot be immutable, of course). The sorting algorithm is stable, which means that equal elements retain the same relative order. One version of sort() uses a specified Comparator to perform the sort; the other relies on the natural ordering of the list elements and requires all the elements to implement java.lang.Comparable.
A related method is binarySearch(). It efficiently (in logarithmic time) searches a sorted List for a specified object and returns the index at which a matching object is found. If no match is found, it returns a negative number. For a negative return value r, the value -(r+1) specifies the index at which the specified object can be inserted into the list to maintain the sorted order of the list. As with sort(), binarySearch() can be passed a Comparator that defines the order of the sorted list. If no Comparator is specified, the list elements must all implement Comparable, and the list is assumed to be sorted according to the natural ordering defined by this interface.
The various methods whose names begin with synchronized return a thread-safe collection object wrapped around the specified collection. Vector and Hashtable are the only two collection objects thread-safe by default. Use these methods to obtain a synchronized wrapper object if you are using any other type of Collection or Map in a multithreaded environment where more than one thread can modify it.
The various methods whose names begin with unmodifiable function like synchronized methods. They return a Collection or Map object wrapped around the specified collection. The returned object is unmodifiable, however, so its add(), remove(), set(), put(), etc., methods all throw java.lang.UnsupportedOperationException.
The Collections class also defines a number of miscellanous methods. copy() copies elements of a source list into a destination list. enumeration() returns an Enumeration for a Collection, which is useful when working with code that uses the old Enumeration interface instead of the newer Iterator interface. fill() replaces all elements of the specified list with the specified object. The min() and max() methods search an unordered Collection for the minimum and maximum elements, according either to a specified Comparator or to the natural order defined by the Comparable elements themselves. nCopies() creates a new immutable List that contains a specified number of copies of a specified object. reverse() reverses the order of the elements in a list. This method operates in place and therefore does not work for immutable lists. reverseOrder() returns a convenient predefined Comparator object that can order Comparable objects into the reverse of their natural ordering. shuffle() randomizes the order of elements in a list, using either an internal source of randomness or the Random pseudo-random number generator you provide. singleton() returns an unmodifiable set that contains only the specified object. The Collections class also defines two related constants, EMPTY_LIST and EMPTY_SET, which are immutable List and Set objects that contain no elements. In Java 1.3, singletonList() and singletonMap() return an immutable list and an immutable map, respectively, each of which contains only a single entry. The Collections class also defines related constants, EMPTY_LIST, EMPTY_SET, and EMPTY_MAP (in Java 1.3), which are immutable List, Set, and Map objects that contain no elements.
See Arrays for methods that perform sorting and searching operations on arrays instead of collections.
public class Collections { | ||
// | No Constructor | |
// | Public Constants | |
public static final java.util.List EMPTY_LIST ; | ||
1.3 | public static final Map EMPTY_MAP ; | |
public static final Set EMPTY_SET ; | ||
// | Public Class Methods | |
public static int binarySearch (java.util.List list, Object key); | ||
public static int binarySearch (java.util.List list, Object key, Comparator c); | ||
public static void copy (java.util.List dest, java.util.List src); | ||
public static Enumeration enumeration (Collection c); | ||
public static void fill (java.util.List list, Object o); | ||
public static Object max (Collection coll); | ||
public static Object max (Collection coll, Comparator comp); | ||
public static Object min (Collection coll); | ||
public static Object min (Collection coll, Comparator comp); | ||
public static java.util.List nCopies (int n, Object o); | ||
public static void reverse (java.util.List l); | ||
public static Comparator reverseOrder (); | ||
public static void shuffle (java.util.List list); | ||
public static void shuffle (java.util.List list, Random rnd); | ||
public static Set singleton (Object o); | ||
1.3 | public static java.util.List singletonList (Object o); | |
1.3 | public static Map singletonMap (Object key, Object value); | |
public static void sort (java.util.List list); | ||
public static void sort (java.util.List list, Comparator c); | ||
public static Collection synchronizedCollection (Collection c); | ||
public static java.util.List synchronizedList (java.util.List list); | ||
public static Map synchronizedMap (Map m); | ||
public static Set synchronizedSet (Set s); | ||
public static SortedMap synchronizedSortedMap (SortedMap m); | ||
public static SortedSet synchronizedSortedSet (SortedSet s); | ||
public static Collection unmodifiableCollection (Collection c); | ||
public static java.util.List unmodifiableList (java.util.List list); | ||
public static Map unmodifiableMap (Map m); | ||
public static Set unmodifiableSet (Set s); | ||
public static SortedMap unmodifiableSortedMap (SortedMap m); | ||
public static SortedSet unmodifiableSortedSet (SortedSet s); | ||
} |
Comparator | Java 1.2 | |
|
||
java.util |
This interface defines a compare() method that specifies a total ordering for a set of objects, allowing those objects to be sorted. The Comparator is used when the objects to be ordered do not have a natural ordering defined by the Comparable interface, or when you want to order them using something other than their natural ordering.
The compare() method is passed two objects. If the first argument is less than the second argument or should be placed before the second argument in a sorted list, compare() should return a negative integer. If the first argument is greater than the second argument or should be placed after the second argument in a sorted list, compare() should return a positive integer. If the two objects are equivalent or if their relative position in a sorted list does not matter, compare() should return 0. Comparator implementations may assume that both Object arguments are of appropriate types and cast them as desired. If either argument is not of the expected type, the compare() method throws a ClassCastException.
Note that the magnitude of the numbers returned by compare() does not matter, only whether they are less than, equal to, or greater than zero. In most cases, you should implement a Comparator so that compare(o1,o2) returns 0 if and only if o1.equals(o2) returns true. This is particularly important when using a Comparator to impose an ordering on a TreeSet or a TreeMap.
See Collections and Arrays for various methods that use Comparator objects for sorting and searching. See also the related java.lang.Comparable interface.
public interface Comparator { | ||
// | Public Instance Methods | |
public abstract int compare (Object o1, Object o2); | ||
public abstract boolean equals (Object obj); | ||
} |
Implementations: java.text.Collator
Passed To: Arrays.{binarySearch(), sort()}, Collections.{binarySearch(), max(), min(), sort()}, TreeMap.TreeMap(), TreeSet.TreeSet()
Returned By: Collections.reverseOrder(), SortedMap.comparator(), SortedSet.comparator(), TreeMap.comparator(), TreeSet.comparator()
Type Of: String.CASE_INSENSITIVE_ORDER
ConcurrentModificationException | Java 1.2 | |
|
||
java.util | serializable unchecked |
Signals that a modification has been made to a data structure at the same time some other operation is in progress and that, as a result, the correctness of the ongoing operation cannot be guaranteed. It is typically thrown by an Iterator or ListIterator object to stop an iteration if it detects that the underlying collection has been modified while the iteration is in progress.
public class ConcurrentModificationException extends RuntimeException { | ||
// | Public Constructors | |
public ConcurrentModificationException (); | ||
public ConcurrentModificationException (String message); | ||
} |
Hierarchy: Object-->Throwable(Serializable)-->Exception-->RuntimeException-->ConcurrentModificationException
Date | Java 1.0 | |
|
||
java.util | cloneable serializable comparable PJ1.1 |
This class represents dates and times and lets you work with them in a system-independent way. You can create a Date by specifying the number of milliseconds from the epoch (midnight GMT, January 1st, 1970) or the year, month, date, and, optionally, the hour, minute, and second. Years are specified as the number of years since 1900. If you call the Date constructor with no arguments, the Date is initialized to the current time and date. The instance methods of the class allow you to get and set the various date and time fields, to compare dates and times, and to convert dates to and from string representations. As of Java 1.1, many of the date methods have been deprecated in favor of the methods of the Calendar class.
public class Date implements Cloneable, Comparable, Serializable { | ||
// | Public Constructors | |
public Date (); | ||
# | public Date (String s); | |
public Date (long date); | ||
# | public Date (int year, int month, int date); | |
# | public Date (int year, int month, int date, int hrs, int min); | |
# | public Date (int year, int month, int date, int hrs, int min, int sec); | |
// | Property Accessor Methods (by property name) | |
public long getTime (); | ||
public void setTime (long time); | ||
// | Public Instance Methods | |
public boolean after (java.util.Date when); | ||
public boolean before (java.util.Date when); | ||
1.2 | public int compareTo (java.util.Date anotherDate); | |
// | Methods Implementing Comparable | |
1.2 | public int compareTo (Object o); | |
// | Public Methods Overriding Object | |
1.2 | public Object clone (); | |
public boolean equals (Object obj); | ||
public int hashCode (); | ||
public String toString (); | ||
// | Deprecated Public Methods | |
# | public int getDate (); | |
# | public int getDay (); | |
# | public int getHours (); | |
# | public int getMinutes (); | |
# | public int getMonth (); | |
# | public int getSeconds (); | |
# | public int getTimezoneOffset (); | |
# | public int getYear (); | |
# | public static long parse (String s); | |
# | public void setDate (int date); | |
# | public void setHours (int hours); | |
# | public void setMinutes (int minutes); | |
# | public void setMonth (int month); | |
# | public void setSeconds (int seconds); | |
# | public void setYear (int year); | |
# | public String toGMTString (); | |
# | public String toLocaleString (); | |
# | public static long UTC (int year, int month, int date, int hrs, int min, int sec); | |
} |
Hierarchy: Object-->java.util.Date(Cloneable,Comparable,Serializable)
Subclasses: java.sql.Date, java.sql.Time, java.sql.Timestamp
Passed To: java.security.cert.X509Certificate.checkValidity(), java.text.DateFormat.format(), java.text.SimpleDateFormat.{format(), set2DigitYearStart()}, Calendar.setTime(), java.util.Date.{after(), before(), compareTo()}, GregorianCalendar.setGregorianChange(), SimpleTimeZone.inDaylightTime(), java.util.Timer.{schedule(), scheduleAtFixedRate()}, TimeZone.inDaylightTime()
Returned By: java.security.KeyStore.getCreationDate(), java.security.KeyStoreSpi.engineGetCreationDate(), java.security.cert.X509Certificate.{getNotAfter(), getNotBefore()}, java.security.cert.X509CRL.{getNextUpdate(), getThisUpdate()}, java.security.cert.X509CRLEntry.getRevocationDate(), java.text.DateFormat.parse(), java.text.SimpleDateFormat.{get2DigitYearStart(), parse()}, Calendar.getTime(), GregorianCalendar.getGregorianChange()
Dictionary | Java 1.0 | |
|
||
java.util | PJ1.1 |
This abstract class is the superclass of Hashtable. Other hashtable-like data structures might also extend this class. See Hashtable for more information. In Java 1.2, the Map interface replaces the functionality of this class.
public abstract class Dictionary { | ||
// | Public Constructors | |
public Dictionary (); | ||
// | Public Instance Methods | |
public abstract Enumeration elements (); | ||
public abstract Object get (Object key); | ||
public abstract boolean isEmpty (); | ||
public abstract Enumeration keys (); | ||
public abstract Object put (Object key, Object value); | ||
public abstract Object remove (Object key); | ||
public abstract int size (); | ||
} |
Subclasses: Hashtable
Passed To: javax.swing.JSlider.setLabelTable(), javax.swing.text.AbstractDocument.setDocumentProperties()
Returned By: javax.swing.JSlider.getLabelTable(), javax.swing.text.AbstractDocument.getDocumentProperties()
EmptyStackException | Java 1.0 | |
|
||
java.util | serializable unchecked PJ1.1 |
Signals that a Stack object is empty.
public class EmptyStackException extends RuntimeException { | ||
// | Public Constructors | |
public EmptyStackException (); | ||
} |
Hierarchy: Object-->Throwable(Serializable)-->Exception-->RuntimeException-->EmptyStackException
Thrown By: java.awt.EventQueue.pop()
Enumeration | Java 1.0 | |
|
||
java.util | PJ1.1 |
This interface defines the methods necessary to enumerate, or iterate, through a set of values, such as the set of values contained in a hashtable or binary tree. It is particularly useful for data structures, like hashtables, for which elements cannot simply be looked up by index, as they can in arrays. An Enumeration is usually not instantiated directly, but instead is created by the object that is to have its values enumerated. A number of classes, such as Vector and Hashtable, have methods that return Enumeration objects. In Java 1.2, the new Iterator interface is preferred over Enumeration.
To use an Enumeration object, you use its two methods in a loop. hasMoreElements() returns true if there are more values to be enumerated and can determine whether a loop should continue. Within a loop, a call to nextElement() returns a value from the enumeration. An Enumeration makes no guarantees about the order in which the values are returned. The values in an Enumeration can be iterated through only once; there is no way to reset it to the beginning.
public interface Enumeration { | ||
// | Public Instance Methods | |
public abstract boolean hasMoreElements (); | ||
public abstract Object nextElement (); | ||
} |
Implementations: StringTokenizer, javax.naming.NamingEnumeration
Passed To: java.io.SequenceInputStream.SequenceInputStream(), javax.naming.CompositeName.CompositeName(), javax.naming.CompoundName.CompoundName(), javax.swing.JTree.removeDescendantToggledPaths(), javax.swing.text.AbstractDocument.AbstractElement.removeAttributes(), javax.swing.text.AbstractDocument.AttributeContext.removeAttributes(), javax.swing.text.MutableAttributeSet.removeAttributes(), javax.swing.text.SimpleAttributeSet.removeAttributes(), javax.swing.text.StyleContext.removeAttributes(), javax.swing.text.StyleContext.NamedStyle.removeAttributes(), javax.swing.text.html.StyleSheet.removeAttributes()
Returned By: Too many methods to list.
Type Of: javax.swing.tree.DefaultMutableTreeNode.EMPTY_ENUMERATION
EventListener | Java 1.1 | |
|
||
java.util | event listener PJ1.1 |
EventListener is a base interface for the event model that is used by AWT and Swing in Java 1.1 and later. This interface defines no methods or constants; it serves simply as a tag that identifies objects that act as event listeners. The event listener interfaces in the java.awt.event, java.beans, and javax.swing.event packages extend this interface.
public interface EventListener { | ||
} |
Implementations: Too many classes to list.
Passed To: java.awt.AWTEventMulticaster.{addInternal(), AWTEventMulticaster(), remove(), removeInternal(), save()}, javax.swing.event.EventListenerList.{add(), remove()}
Returned By: Too many methods to list.
Type Of: java.awt.AWTEventMulticaster.{a, b}
EventObject | Java 1.1 | |
|
||
java.util | serializable event PJ1.1 |
EventObject serves as the superclass for all event objects used by the event model introduced in Java 1.1 for AWT and JavaBeans and also used by Swing in Java 1.2. This class defines a generic type of event; it is extended by the more specific event classes in the java.awt, java.awt.event, java.beans, and javax.swing.event packages. The only common feature shared by all events is a source object, which is the object that, in some way, generated the event. The source object is passed to the EventObject() constructor and is returned by the getSource() method.
public class EventObject implements Serializable { | ||
// | Public Constructors | |
public EventObject (Object source); | ||
// | Public Instance Methods | |
public Object getSource (); | ||
// | Public Methods Overriding Object | |
public String toString (); | ||
// | Protected Instance Fields | |
protected transient Object source ; | ||
} |
Hierarchy: Object-->EventObject(Serializable)
Subclasses: Too many classes to list.
Passed To: javax.swing.AbstractCellEditor.{isCellEditable(), shouldSelectCell()}, javax.swing.CellEditor.{isCellEditable(), shouldSelectCell()}, javax.swing.DefaultCellEditor.{isCellEditable(), shouldSelectCell()}, javax.swing.DefaultCellEditor.EditorDelegate.{isCellEditable(), shouldSelectCell(), startCellEditing()}, javax.swing.JTable.editCellAt(), javax.swing.tree.DefaultTreeCellEditor.{canEditImmediately(), isCellEditable(), shouldSelectCell(), shouldStartEditingTimer()}
GregorianCalendar | Java 1.1 | |
|
||
java.util | cloneable serializable PJ1.1 |
This concrete subclass of Calendar implements the standard solar calendar with years numbered from the birth of Christ that is used is most locales throughout the world. You do not typically use this class directly, but instead obtain a Calendar object suitable for the default locale by calling Calendar.getInstance(). See Calendar for details on working with Calendar objects. There is a discontinuity in the Gregorian calendar that represents the historical switch from the Julian calendar to the Gregorian calendar. By default, GregorianCalendar assumes that this switch occurs on October 15, 1582. Most programs need not be concerned with the switch.
public class GregorianCalendar extends Calendar { | ||
// | Public Constructors | |
public GregorianCalendar (); | ||
public GregorianCalendar (TimeZone zone); | ||
public GregorianCalendar (Locale aLocale); | ||
public GregorianCalendar (TimeZone zone, Locale aLocale); | ||
public GregorianCalendar (int year, int month, int date); | ||
public GregorianCalendar (int year, int month, int date, int hour, int minute); | ||
public GregorianCalendar (int year, int month, int date, int hour, int minute, int second); | ||
// | Public Constants | |
public static final int AD ; | =1 | |
public static final int BC ; | =0 | |
// | Public Instance Methods | |
public final java.util.Date getGregorianChange (); | ||
public boolean isLeapYear (int year); | ||
public void setGregorianChange (java.util.Date date); | ||
// | Public Methods Overriding Calendar | |
public void add (int field, int amount); | ||
public boolean equals (Object obj); | ||
1.2 | public int getActualMaximum (int field); | |
1.2 | public int getActualMinimum (int field); | |
public int getGreatestMinimum (int field); | ||
public int getLeastMaximum (int field); | ||
public int getMaximum (int field); | ||
public int getMinimum (int field); | ||
public int hashCode (); | ||
public void roll (int field, boolean up); | ||
public void roll (int field, int amount); | ||
// | Protected Methods Overriding Calendar | |
protected void computeFields (); | ||
protected void computeTime (); | ||
} |
Hierarchy: Object-->Calendar(Cloneable,Serializable)-->GregorianCalendar
HashMap | Java 1.2 | |
|
||
java.util | cloneable serializable collection |
This class implements the Map interface using an internal hashtable. It supports all optional Map methods, allows key and value objects of any types, and allows null to be used as a key or a value. Because HashMap is based on a hashtable data structure, the get() and put() methods are very efficient. HashMap is much like the Hashtable class, except that the HashMap methods are not synchronized (and are therefore faster), and HashMap allows null to be used as a key or a value. If you are working in a multithreaded environment, or if compatibility with previous versions of Java is a concern, use Hashtable. Otherwise, use HashMap.
If you know in advance approximately how many mappings a HashMap will contain, you can improve efficiency by specifying initialCapacity when you call the HashMap() constructor. The initialCapacity argument times the loadFactor argument should be greater than the number of mappings the HashMap will contain. A good value for loadFactor is 0.75; this is also the default value. See Map for details on the methods of HashMap. See also TreeMap and HashSet.
public class HashMap extends AbstractMap implements Cloneable, Map, Serializable { | ||
// | Public Constructors | |
public HashMap (); | ||
public HashMap (int initialCapacity); | ||
public HashMap (Map t); | ||
public HashMap (int initialCapacity, float loadFactor); | ||
// | Methods Implementing Map | |
public void clear (); | ||
public boolean containsKey (Object key); | ||
public boolean containsValue (Object value); | ||
public Set entrySet (); | ||
public Object get (Object key); | ||
public boolean isEmpty (); | default:true | |
public Set keySet (); | ||
public Object put (Object key, Object value); | ||
public void putAll (Map t); | ||
public Object remove (Object key); | ||
public int size (); | ||
public Collection values (); | ||
// | Public Methods Overriding Object | |
public Object clone (); | ||
} |
Hierarchy: Object-->AbstractMap(Map)-->HashMap(Cloneable,Map,Serializable)
Type Of: java.beans.beancontext.BeanContextServicesSupport.services, java.beans.beancontext.BeanContextSupport.children
HashSet | Java 1.2 | |
|
||
java.util | cloneable serializable collection |
This class implements Set using an internal hashtable. It supports all optional Set and Collection methods and allows any type of object or null to be a member of the set. Because HashSet is based on a hashtable, the basic add(), remove(), and contains() methods are all quite efficient. HashSet makes no guarantee about the order in which the set elements are enumerated by the Iterator returned by iterator(). The methods of HashSet are not synchronized. If you are using it in a multithreaded environment, you must explicitly synchronize all code that modifies the set or obtain a synchronized wrapper for it by calling Collections.synchronizedSet().
If you know in advance approximately how many mappings a HashSet will contain, you can improve efficiency by specifying initialCapacity when you call the HashSet() constructor. The initialCapacity argument times the loadFactor argument should be greater than the number of mappings the HashSet will contain. A good value for loadFactor is 0.75; this is also the default value. See Set and Collection for details on the methods of HashSet. See also TreeSet and HashMap.
public class HashSet extends AbstractSet implements Cloneable, Serializable, Set { | ||
// | Public Constructors | |
public HashSet (); | ||
public HashSet (int initialCapacity); | ||
public HashSet (Collection c); | ||
public HashSet (int initialCapacity, float loadFactor); | ||
// | Methods Implementing Set | |
public boolean add (Object o); | ||
public void clear (); | ||
public boolean contains (Object o); | ||
public boolean isEmpty (); | default:true | |
public Iterator iterator (); | ||
public boolean remove (Object o); | ||
public int size (); | ||
// | Public Methods Overriding Object | |
public Object clone (); | ||
} |
Hierarchy: Object-->AbstractCollection(Collection)-->AbstractSet(Set(Collection))-->HashSet(Cloneable,Serializable,Set(Collection))
Hashtable | Java 1.0 | |
|
||
java.util | cloneable serializable collection PJ1.1 |
This class implements a hashtable data structure, which maps key objects to value objects and allows the efficient lookup of the value associated with a given key. put() associates a value with a key in a Hashtable. get() retrieves a value for a specified key. remove() deletes a key/value association. keys() and elements() return Enumeration objects that allow you to iterate through the complete set of keys and values stored in the table. Objects used as keys in a Hashtable must have valid equals() and hashCode() methods (the versions inherited from Object are okay). null is not legal as a key or value in a Hashtable.
Hashtable is a commonly used class and has been a part of the Java API since Java 1.0. In Java 1.2, it has been enhanced to implement the Map interface, which defines some functionality in addition to the Java 1.0 Hashtable methods. Hashtable is very similar to the HashMap class, but has synchronized methods, which make it thread-safe but increase the overhead associated with it. If you need thread safety or require compatibility with Java 1.0 or Java 1.1, use Hashtable. Otherwise, use HashMap.
public class Hashtable extends Dictionary implements Cloneable, Map,Serializable { | ||
// | Public Constructors | |
public Hashtable (); | ||
1.2 | public Hashtable (Map t); | |
public Hashtable (int initialCapacity); | ||
public Hashtable (int initialCapacity, float loadFactor); | ||
// | Public Instance Methods | |
public boolean contains (Object value); | synchronized | |
// | Methods Implementing Map | |
public void clear (); | synchronized | |
public boolean containsKey (Object key); | synchronized | |
1.2 | public boolean containsValue (Object value); | |
1.2 | public Set entrySet (); | |
1.2 | public boolean equals (Object o); | synchronized |
public Object get (Object key); | synchronized | |
1.2 | public int hashCode (); | synchronized |
public boolean isEmpty (); | default:true | |
1.2 | public Set keySet (); | |
public Object put (Object key, Object value); | synchronized | |
1.2 | public void putAll (Map t); | synchronized |
public Object remove (Object key); | synchronized | |
public int size (); | ||
1.2 | public Collection values (); | |
// | Public Methods Overriding Dictionary | |
public Enumeration elements (); | synchronized | |
public Enumeration keys (); | synchronized | |
// | Public Methods Overriding Object | |
public Object clone (); | synchronized | |
public String toString (); | synchronized | |
// | Protected Instance Methods | |
protected void rehash (); | ||
} |
Hierarchy: Object-->Dictionary-->Hashtable(Cloneable,Map,Serializable)
Subclasses: Properties, javax.swing.UIDefaults
Passed To: Too many methods to list.
Returned By: javax.naming.CannotProceedException.getEnvironment(), javax.naming.Context.getEnvironment(), javax.naming.InitialContext.getEnvironment(), javax.servlet.http.HttpUtils.{parsePostData(), parseQueryString()}, javax.swing.JLayeredPane.getComponentToLayer(), javax.swing.JSlider.createStandardLabels()
Type Of: java.awt.GridBagLayout.comptable, javax.naming.CannotProceedException.environment, javax.naming.InitialContext.myProps, javax.swing.JTable.{defaultEditorsByColumnClass, defaultRenderersByColumnClass}, javax.swing.text.html.parser.DTD.{elementHash, entityHash}, javax.swing.undo.StateEdit.{postState, preState}
Iterator | Java 1.2 | |
|
||
java.util |
This interface defines methods for iterating, or enumerating, the elements of a collection. The hasNext() method returns true if there are more elements to be enumerated or false if all elements have already been returned. The next() method returns the next element. These two methods make it easy to loop through an iterator with code such as the following:
for(Iterator i = c.iterator(); i.hasNext(); ) processObject(i.next());
The Iterator interface is much like the Enumeration interface. In Java 1.2, Iterator is preferred over Enumeration because it provides a well-defined way to safely remove elements from a collection while the iteration is in progress. The remove() method removes the object most recently returned by next() from the collection that is being iterated through. Note, however, that support for remove() is optional; if an Iterator does not support remove(), it throws a java.lang.UnsupportedOperationException when you call it. While you are iterating through a collection, you are allowed to modify the collection only by calling the remove() method of the Iterator. If the collection is modified in any other way while an iteration is ongoing, the Iterator may fail to operate correctly,x or it may throw a ConcurrentModificationException.
public interface Iterator { | ||
// | Public Instance Methods | |
public abstract boolean hasNext (); | ||
public abstract Object next (); | ||
public abstract void remove (); | ||
} |
Implementations: java.beans.beancontext.BeanContextSupport.BCSIterator, ListIterator
Returned By: Too many methods to list.
LinkedList | Java 1.2 | |
|
||
java.util | cloneable serializable collection |
This class implements the List interface in terms of a doubly linked list. It supports all optional methods of List and Collection and allows list elements of any type, including null. Because LinkedList is implemented with a linked list data structure, the get() and set() methods are substantially less efficient than the same methods for an ArrayList. However, a LinkedList may be more efficient when the add() and remove() methods are used frequently. The methods of LinkedList are not synchronized. If you are using a LinkedList in a multithreaded environment, you must explicitly synchronize any code that modifies the list or obtain a synchronized wrapper object with Collections.synchronizedList().
In addition to the methods defined by the List interface, LinkedList defines methods to get the first and last elements of the list, to add an element to the beginning or end of the list, and to remove the first or last element of the list. These convenient and efficient methods make LinkedList well-suited for use as a stack or queue. See List and Collection for details on the methods of LinkedList. See also ArrayList.
public class LinkedList extends AbstractSequentialList implements Cloneable, java.util.List, Serializable { | ||
// | Public Constructors | |
public LinkedList (); | ||
public LinkedList (Collection c); | ||
// | Public Instance Methods | |
public void addFirst (Object o); | ||
public void addLast (Object o); | ||
public Object getFirst (); | ||
public Object getLast (); | ||
public Object removeFirst (); | ||
public Object removeLast (); | ||
// | Methods Implementing List | |
public boolean add (Object o); | ||
public void add (int index, Object element); | ||
public boolean addAll (Collection c); | ||
public boolean addAll (int index, Collection c); | ||
public void clear (); | ||
public boolean contains (Object o); | ||
public Object get (int index); | ||
public int indexOf (Object o); | ||
public int lastIndexOf (Object o); | ||
public ListIterator listIterator (int index); | ||
public boolean remove (Object o); | ||
public Object remove (int index); | ||
public Object set (int index, Object element); | ||
public int size (); | ||
public Object[ ] toArray (); | ||
public Object[ ] toArray (Object[ ] a); | ||
// | Public Methods Overriding Object | |
public Object clone (); | ||
} |
Hierarchy: Object-->AbstractCollection(Collection)-->AbstractList(java.util.List(Collection))-->AbstractSequentialList-->LinkedList(Cloneable,java.util.List(Collection),Serializable)
List | Java 1.2 | |
|
||
java.util | collection |
This interface represents an ordered collection of objects. Each element in a List has an index, or position, in the list, and elements can be inserted, queried, and removed by index. The first element of a List has an index of 0. The last element in a list has index size()-1.
In addition to the methods defined by the superinterface, Collection, List defines a number of methods for working with its indexed elements. get() and set() query and set the object at a particular index, respectively. Versions of add() and addAll() that take an index argument insert an object or Collection of objects at a specified index. The versions of add() and addAll() that do not take an index argument insert an object or collection of objects at the end of the list. List defines a version of remove() that removes the object at a specified index.
The iterator() method is just like the iterator() method of Collection, except that the Iterator it returns is guaranteed to enumerate the elements of the List in order. listIterator() returns a ListIterator object, which is more powerful than a regular Iterator and allows the list to be modified while iteration proceeds. listIterator() can take an index argument to specify where in the list iteration should begin.
indexOf() and lastIndexOf() perform linear searches from the beginning and end, respectively, of the list, searching for a specified object. Each method returns the index of the first matching object it finds, or -1 if it does not find a match. Finally, subList() returns a List that contains only a specified contiguous range of list elements. The returned list is simply a view into the original list, so changes in the original List are visible in the returned List. This subList() method is particularly useful if you want to sort, search, clear(), or otherwise manipulate only a partial range of a larger list.
An interface cannot specify constructors, but it is conventional that all implementations of List provide at least two standard constructors: one that takes no arguments and creates an empty list, and a copy constructor that accepts an arbitrary Collection object that specifies the initial contents of the new List.
As with Collection, all List methods that change the contents of the list are optional, and implementations that do not support them simply throw java.lang.UnsupportedOperationException. Different implementations of List may have significantly different efficiency characteristics. For example, the get() and set() methods of an ArrayList are much more efficient than those of a LinkedList. On the other hand, the add() and remove() methods of a LinkedList can be more efficient than those of an ArrayList. See also Collection, Set, Map, ArrayList, and LinkedList.
public interface List extends Collection { | ||
// | Public Instance Methods | |
public abstract boolean add (Object o); | ||
public abstract void add (int index, Object element); | ||
public abstract boolean addAll (Collection c); | ||
public abstract boolean addAll (int index, Collection c); | ||
public abstract void clear (); | ||
public abstract boolean contains (Object o); | ||
public abstract boolean containsAll (Collection c); | ||
public abstract boolean equals (Object o); | ||
public abstract Object get (int index); | ||
public abstract int hashCode (); | ||
public abstract int indexOf (Object o); | ||
public abstract boolean isEmpty (); | ||
public abstract Iterator iterator (); | ||
public abstract int lastIndexOf (Object o); | ||
public abstract ListIterator listIterator (); | ||
public abstract ListIterator listIterator (int index); | ||
public abstract boolean remove (Object o); | ||
public abstract Object remove (int index); | ||
public abstract boolean removeAll (Collection c); | ||
public abstract boolean retainAll (Collection c); | ||
public abstract Object set (int index, Object element); | ||
public abstract int size (); | ||
public abstract java.util.List subList (int fromIndex, int toIndex); | ||
public abstract Object[ ] toArray (); | ||
public abstract Object[ ] toArray (Object[ ] a); | ||
} |
Hierarchy: (java.util.List(Collection))
Implementations: AbstractList, ArrayList, LinkedList, Vector
Passed To: java.awt.dnd.DragGestureEvent.DragGestureEvent(), Collections.{binarySearch(), copy(), fill(), reverse(), shuffle(), sort(), synchronizedList(), unmodifiableList()}
Returned By: java.awt.dnd.DropTargetContext.getCurrentDataFlavorsAsList(), java.awt.dnd.DropTargetDragEvent.getCurrentDataFlavorsAsList(), java.awt.dnd.DropTargetDropEvent.getCurrentDataFlavorsAsList(), AbstractList.subList(), Arrays.asList(), Collections.{nCopies(), singletonList(), synchronizedList(), unmodifiableList()}, java.util.List.subList(), Vector.subList()
Type Of: Collections.EMPTY_LIST
ListIterator | Java 1.2 | |
|
||
java.util |
This interface is an extension of Iterator for use with ordered collections, or lists. It defines methods to iterate forward and backward through a list, to determine the list index of the elements being iterated, and, for mutable lists, to safely insert, delete, and edit elements in the list while the iteration is in progress. For some lists, notably LinkedList, using an iterator to enumerate the list's elements may be substantially more efficient than looping through the list by index and calling get() repeatedly.
hasNext() and next() are the most commonly used methods of ListIterator; they iterate forward through the list. See Iterator for details. In addition to these two methods, however, ListIterator also defines hasPrevious() and previous() that allow you to iterate backward through the list. previous() returns the previous element on the list or throws a NoSuchElementException if there is no previous element. hasPrevious() returns true if a subsequent call to previous() returns an object. nextIndex() and previousIndex() return the index of the object that would be returned by a subsequent call to next() or previous(). If next() or previous() throw a NoSuchElementException, nextIndex() returns the size of the list, and previousIndex() returns -1.
ListIterator defines three optionally supported methods that provide a safe way to modify the contents of the underlying list while the iteration is in progress. add() inserts a new object into the list, immediately before the object that would be returned by a subsequent call to next(). Calling add() does not affect the value that is returned by next(), however. If you call previous() immediately after calling add(), the method returns the object you just added. remove() deletes from the list the object most recently returned by next() or previous(). You can only call remove() once per call to next() or previous(). If you have called add(), you must call next() or previous() again before calling remove(). set() replaces the object most recently returned by next() or previous() with the specified object. If you have called add() or remove(), you must call next() or previous() again before calling set(). Remember that support for the add(), remove(), and set() methods is optional. Iterators for immutable lists never support them, of course. An unsupported method throws a java.lang.UnsupportedOperationException when called. Also, when an iterator is in use, all modifications should be made through the iterator rather than to the list itself. If the underlying list is modified while an iteration is ongoing, the ListIterator may fail to operate correctly or may throw a ConcurrentModificationException.
public interface ListIterator extends Iterator { | ||
// | Public Instance Methods | |
public abstract void add (Object o); | ||
public abstract boolean hasNext (); | ||
public abstract boolean hasPrevious (); | ||
public abstract Object next (); | ||
public abstract int nextIndex (); | ||
public abstract Object previous (); | ||
public abstract int previousIndex (); | ||
public abstract void remove (); | ||
public abstract void set (Object o); | ||
} |
Hierarchy: (ListIterator(Iterator))
Returned By: AbstractList.listIterator(), AbstractSequentialList.listIterator(), LinkedList.listIterator(), java.util.List.listIterator()
ListResourceBundle | Java 1.1 | |
|
||
java.util | PJ1.1 |
This abstract class provides a simple way to define a ResourceBundle. You may find it easier to subclass ListResourceBundle than to subclass ResourceBundle directly. ListResourceBundle provides implementations for the abstract handleGetObject() and getKeys() methods defined by ResourceBundle and adds its own abstract getContents() method a subclass must override. getContents() returns an Object[][]--an array of arrays of objects. This array can have any number of elements. Each element of this array must itself be an array with two elements: the first element of each subarray should be a String that specifies the name of a resource, and the corresponding second element should be the value of that resource; this value can be an Object of any desired type. See also ResourceBundle and PropertyResourceBundle.
public abstract class ListResourceBundle extends ResourceBundle { | ||
// | Public Constructors | |
public ListResourceBundle (); | ||
// | Public Methods Overriding ResourceBundle | |
public Enumeration getKeys (); | ||
public final Object handleGetObject (String key); | ||
// | Protected Instance Methods | |
protected abstract Object[ ][ ] getContents (); | ||
} |
Hierarchy: Object-->ResourceBundle-->ListResourceBundle
Subclasses: java.text.resources.DateFormatZoneData, java.text.resources.DateFormatZoneData_en, java.text.resources.LocaleElements, java.text.resources.LocaleElements_en, java.text.resources.LocaleElements_en_US, javax.accessibility.AccessibleResourceBundle
Locale | Java 1.1 | |
|
||
java.util | cloneable serializable PJ1.1 |
The Locale class represents a locale: a political, geographical, or cultural region that typically has a distinct language and distinct customs and conventions for such things as formatting dates, times, and numbers. The Locale class defines a number of constants that represent commonly used locales. Locale also defines a static getDefault() method that returns the default Locale object, which represents a locale value inherited from the host system. getAvailableLocales() returns the list of all locales supported by the underlying system. If none of these methods for obtaining a Locale object are suitable, you can explicitly create your own Locale object. To do this, you must specify a language code, a country code, and an optional variant string. getISOCountries() and getISOLanguages() return the list of supported country codes and language codes.
The Locale class does not implement any internationalization behavior itself; it merely serves as a locale identifier for those classes that can localize their behavior. Given a Locale object, you can invoke the various getDisplay methods to obtain a description of the locale suitable for display to a user. These methods may themselves take a Locale argument, so the names of languages and countries can be localized as appropriate.
public final class Locale implements Cloneable, Serializable { | ||
// | Public Constructors | |
public Locale (String language, String country); | ||
public Locale (String language, String country, String variant); | ||
// | Public Constants | |
public static final Locale CANADA ; | ||
public static final Locale CANADA_FRENCH ; | ||
public static final Locale CHINA ; | ||
public static final Locale CHINESE ; | ||
public static final Locale ENGLISH ; | ||
public static final Locale FRANCE ; | ||
public static final Locale FRENCH ; | ||
public static final Locale GERMAN ; | ||
public static final Locale GERMANY ; | ||
public static final Locale ITALIAN ; | ||
public static final Locale ITALY ; | ||
public static final Locale JAPAN ; | ||
public static final Locale JAPANESE ; | ||
public static final Locale KOREA ; | ||
public static final Locale KOREAN ; | ||
public static final Locale PRC ; | ||
public static final Locale SIMPLIFIED_CHINESE ; | ||
public static final Locale TAIWAN ; | ||
public static final Locale TRADITIONAL_CHINESE ; | ||
public static final Locale UK ; | ||
public static final Locale US ; | ||
// | Public Class Methods | |
1.2 | public static Locale[ ] getAvailableLocales (); | |
public static Locale getDefault (); | ||
1.2 | public static String[ ] getISOCountries (); | |
1.2 | public static String[ ] getISOLanguages (); | |
public static void setDefault (Locale newLocale); | synchronized | |
// | Property Accessor Methods (by property name) | |
public String getCountry (); | ||
public final String getDisplayCountry (); | ||
public String getDisplayCountry (Locale inLocale); | ||
public final String getDisplayLanguage (); | ||
public String getDisplayLanguage (Locale inLocale); | ||
public final String getDisplayName (); | ||
public String getDisplayName (Locale inLocale); | ||
public final String getDisplayVariant (); | ||
public String getDisplayVariant (Locale inLocale); | ||
public String getISO3Country () throws MissingResourceException; | ||
public String getISO3Language () throws MissingResourceException; | ||
public String getLanguage (); | ||
public String getVariant (); | ||
// | Public Methods Overriding Object | |
public Object clone (); | ||
public boolean equals (Object obj); | ||
public int hashCode (); | synchronized | |
public final String toString (); | ||
} |
Hierarchy: Object-->Locale(Cloneable,Serializable)
Passed To: Too many methods to list.
Returned By: Too many methods to list.
Type Of: Too many fields to list.
Map | Java 1.2 | |
|
||
java.util | collection |
This interface represents a collection of mappings, or associations, between key objects and value objects. Hashtables and associative arrays are examples of maps. The set of key objects in a Map must not have any duplicates; the collection of value objects is under no such constraint. The key objects should usually be immutable objects, or, if they are not, care should be taken that they do not change while in use in a Map. As of Java 1.2, the Map interface replaces the abstract Dictionary class. Although a Map is not a Collection, the Map interface is still considered an integral part, along with Set, List, and others, of the Java collections framework.
You can add a key/value association to a Map with the put() method. Use putAll() to copy all mappings from one Map to another. Call get() to look up the value object associated with a specified key object. Use remove() to delete the mapping between a specified key and its value, or use clear() to delete all mappings from a Map. size() returns the number of mappings in a Map, and isEmpty() tests whether the Map contains no mappings. containsKey() tests whether a Map contains the specified key object, and containsValue() tests whether it contains the specified value. (For most implementations, containsValue() is a much more expensive operation than containsKey(), however.) keySet() returns a Set of all key objects in the Map. values() returns a Collection (not a Set, since it may contain duplicates) of all value objects in the map. entrySet() returns a Set of all mappings in a Map. The elements of this returned Set are Map.Entry objects. The collections returned by values(), keySet(), and entrySet() are based on the Map itself, so changes to the Map are reflected in the collections.
An interface cannot specify constructors, but it is conventional that all implementations of Map provide at least two standard constructors: one that takes no arguments and creates an empty map, and a copy constructor that accepts a Map object that specifies the initial contents of the new Map.
Implementations are required to support all methods that query the contents of a Map, but support for methods that modify the contents of a Map is optional. If an implementation does not support a particular method, the implementation of that method simply throws a java.lang.UnsupportedOperationException. See also Collection, Set, List, HashMap, Hashtable, WeakHashMap, SortedMap, and TreeMap.
public interface Map { | ||
// | Inner Classes | |
; | ||
// | Public Instance Methods | |
public abstract void clear (); | ||
public abstract boolean containsKey (Object key); | ||
public abstract boolean containsValue (Object value); | ||
public abstract Set entrySet (); | ||
public abstract boolean equals (Object o); | ||
public abstract Object get (Object key); | ||
public abstract int hashCode (); | ||
public abstract boolean isEmpty (); | ||
public abstract Set keySet (); | ||
public abstract Object put (Object key, Object value); | ||
public abstract void putAll (Map t); | ||
public abstract Object remove (Object key); | ||
public abstract int size (); | ||
public abstract Collection values (); | ||
} |
Implementations: java.awt.RenderingHints, AbstractMap, HashMap, Hashtable, SortedMap, WeakHashMap, java.util.jar.Attributes
Passed To: Too many methods to list.
Returned By: java.awt.Font.getAttributes(), java.awt.Toolkit.mapInputMethodHighlight(), java.awt.datatransfer.FlavorMap.{getFlavorsForNatives(), getNativesForFlavors()}, java.awt.datatransfer.SystemFlavorMap.{getFlavorsForNatives(), getNativesForFlavors()}, java.awt.im.InputMethodHighlight.getStyle(), java.sql.Connection.getTypeMap(), java.text.AttributedCharacterIterator.getAttributes(), Collections.{singletonMap(), synchronizedMap(), unmodifiableMap()}, java.util.jar.Manifest.getEntries(), javax.sql.RowSet.getTypeMap()
Type Of: java.awt.Toolkit.desktopProperties, Collections.EMPTY_MAP, java.util.jar.Attributes.map
Map.Entry | Java 1.2 | |
|
||
java.util |
This interface represents a single mapping, or association, between a key object and a value object in a Map. The entrySet() method of a Map returns a Set of Map.Entry objects that represent the set of mappings in the map. Use the iterator() method of that Set to enumerate these Map.Entry objects. Use getKey() and getValue() to obtain the key and value objects for the entry. Use the optionally supported setValue() method to change the value of an entry. This method throws a java.lang.UnsupportedOperationException if it is not supported by the implementation.
public static interface Map.Entry { | ||
// | Public Instance Methods | |
public abstract boolean equals (Object o); | ||
public abstract Object getKey (); | ||
public abstract Object getValue (); | ||
public abstract int hashCode (); | ||
public abstract Object setValue (Object value); | ||
} |
MissingResourceException | Java 1.1 | |
|
||
java.util | serializable unchecked PJ1.1 |
Signals that no ResourceBundle can be located for the desired locale or that a named resource cannot be found within a given ResourceBundle. getClassName() returns the name of the ResourceBundle class in question, and getKey() returns the name of the resource that cannot be located.
public class MissingResourceException extends RuntimeException { | ||
// | Public Constructors | |
public MissingResourceException (String s, String className, String key); | ||
// | Public Instance Methods | |
public String getClassName (); | ||
public String getKey (); | ||
} |
Hierarchy: Object-->Throwable(Serializable)-->Exception-->RuntimeException-->MissingResourceException
Thrown By: Locale.{getISO3Country(), getISO3Language()}, ResourceBundle.{getBundle(), getObject(), getString(), getStringArray(), handleGetObject()}
NoSuchElementException | Java 1.0 | |
|
||
java.util | serializable unchecked PJ1.1 |
Signals that there are no elements in an object (such as a Vector) or that there are no more elements in an object (such as an Enumeration).
public class NoSuchElementException extends RuntimeException { | ||
// | Public Constructors | |
public NoSuchElementException (); | ||
public NoSuchElementException (String s); | ||
} |
Hierarchy: Object-->Throwable(Serializable)-->Exception-->RuntimeException-->NoSuchElementException
Observable | Java 1.0 | |
|
||
java.util | PJ1.1 |
This class is the superclass of all observable objects to be used in an object-oriented model/view paradigm. The class methods allow you to add and delete Observer objects on the list maintained by an Observable object and to notify all of the Observer objects on the list. Observer objects are notified by invoking their update() methods. Observable also maintains an internal changed flag that can be set and cleared by the Observable itself and queried with hasChanged() by any interested observer.
public class Observable { | ||
// | Public Constructors | |
public Observable (); | ||
// | Public Instance Methods | |
public void addObserver (Observer o); | synchronized | |
public int countObservers (); | synchronized | |
public void deleteObserver (Observer o); | synchronized | |
public void deleteObservers (); | synchronized | |
public boolean hasChanged (); | synchronized | |
public void notifyObservers (); | ||
public void notifyObservers (Object arg); | ||
// | Protected Instance Methods | |
protected void clearChanged (); | synchronized | |
protected void setChanged (); | synchronized | |
} |
Passed To: Observer.update()
Observer | Java 1.0 | |
|
||
java.util | PJ1.1 |
This interface defines the update() method required for an object to observe subclasses of Observable. An Observer registers interest in an Observable object by calling the addObserver() method of Observable. Observer objects that have been registered in this way have their update() methods invoked by the Observable when that object has changed.
public interface Observer { | ||
// | Public Instance Methods | |
public abstract void update (Observable o, Object arg); | ||
} |
Passed To: Observable.{addObserver(), deleteObserver()}
Properties | Java 1.0 | |
|
||
java.util | cloneable serializable collection PJ1.1 |
This class is an extension of Hashtable that allows key/value pairs to be read from and written to a stream. The Properties class implements the system properties list, which supports user customization by allowing programs to look up the values of named resources. Because the load() and store() methods provide an easy way to read and write properties from and to a text stream, this class provides a convenient way to implement an application configuration file.
When you create a Properties object, you may specify another Properties object that contains default values. Keys (property names) and values are associated in a Properties object with the Hashtable method put(). Values are looked up with getProperty(); if this method does not find the key in the current Properties object, it looks in the default Properties object that was passed to the constructor method. A default value can also be specified, in case the key is not found at all. Use setProperty() to add a property name/value pair to the Properties object. This Java 1.2 method is preferred over the inherited put() method because it enforces the constraint that property names and values be strings.
propertyNames() returns an enumeration of all property names (keys) stored in the Properties object and (recursively) all property names stored in the default Properties object associated with it. list() prints the properties stored in a Properties object, which can be useful for debugging. store() writes a Properties object to a stream, writing one property per line, in name=value format. As of Java 1.2, store() is preferred over the deprecated save() method, which writes properties in the same way but suppresses any I/O exceptions that may be thrown in the process. The second argument to both store() and save() is a comment that is written out at the beginning of the property file. Finally, load() reads key/value pairs from a stream and stores them in a Properties object. It is suitable for reading both properties written with store() and hand-edited properties files.
public class Properties extends Hashtable { | ||
// | Public Constructors | |
public Properties (); | ||
public Properties (Properties defaults); | ||
// | Public Instance Methods | |
public String getProperty (String key); | ||
public String getProperty (String key, String defaultValue); | ||
public void list (java.io.PrintStream out); | ||
1.1 | public void list (java.io.PrintWriter out); | |
public void load (java.io.InputStream inStream) throws java.io.IOException; | synchronized | |
public Enumeration propertyNames (); | ||
1.2 | public Object setProperty (String key, String value); | synchronized |
1.2 | public void store (java.io.OutputStream out, String header) throws java.io.IOException; | synchronized |
// | Protected Instance Fields | |
protected Properties defaults ; | ||
// | Deprecated Public Methods | |
# | public void save (java.io.OutputStream out, String header); | synchronized |
} |
Hierarchy: Object-->Dictionary-->Hashtable(Cloneable,Map,Serializable)-->Properties
Subclasses: java.security.Provider
Passed To: java.awt.Toolkit.getPrintJob(), System.setProperties(), java.rmi.activation.ActivationGroupDesc.ActivationGroupDesc(), java.sql.Driver.{connect(), getPropertyInfo()}, java.sql.DriverManager.getConnection(), Properties.Properties(), javax.ejb.deployment.DeploymentDescriptor.setEnvironmentProperties(), javax.naming.CompoundName.CompoundName(), org.omg.CORBA.ORB.{init(), set_parameters()}
Returned By: System.getProperties(), java.rmi.activation.ActivationGroupDesc.getPropertyOverrides(), javax.ejb.EJBContext.getEnvironment(), javax.ejb.deployment.DeploymentDescriptor.getEnvironmentProperties()
Type Of: Properties.defaults, javax.naming.CompoundName.mySyntax
PropertyPermission | Java 1.2 | |
|
||
java.util | serializable permission |
This class is a java.security.Permission that governs read and write access to system properties with System.getProperty() and System.setProperty(). A PropertyPermission object has a name, or target, and a comma-separated list of actions. The name of the permission is the name of the property of interest. The action string can be "read" for getProperty() access, "write" for setProperty() access, or "read,write" for both types of access. PropertyPermission extends java.security.BasicPermission, so the name of the property supports simple wildcards. The name "*" represents any property name. If a name ends with ".*", it represents any property names that share the specified prefix. For example, the name "java.*" represents "java.version", "java.vendor", "java.vendor.url", and all other properties that begin with "java".
Granting access to system properties is not overtly dangerous, but caution is still necessary. Some properties, such as "user.home", reveal details about the host system that malicious code can use to mount an attack. Programmers writing system-level code and system administrators configuring security policies may need to use this class, but applications never need to use it.
public final class PropertyPermission extends java.security.BasicPermission { | ||
// | Public Constructors | |
public PropertyPermission (String name, String actions); | ||
// | Public Methods Overriding BasicPermission | |
public boolean equals (Object obj); | ||
public String getActions (); | ||
public int hashCode (); | ||
public boolean implies (java.security.Permission p); | ||
public java.security.PermissionCollection newPermissionCollection (); | ||
} |
Hierarchy: Object-->java.security.Permission(java.security.Guard,Serializable)-->java.security.BasicPermission(Serializable)-->PropertyPermission
PropertyResourceBundle | Java 1.1 | |
|
||
java.util | PJ1.1 |
This class is a concrete subclass of ResourceBundle. It reads a Properties file from a specified InputStream and implements the ResourceBundle API for looking up named resources from the resulting Properties object. A Properties file contains lines of the form:
name=value
Each such line defines a named property with the specified String value. Although you can instantiate a PropertyResourceBundle yourself, it is more common to simply define a Properties file and then allow ResourceBundle.getBundle() to look up that file and return the necessary PropertyResourceBundle object. See also Properties and ResourceBundle.
public class PropertyResourceBundle extends ResourceBundle { | ||
// | Public Constructors | |
public PropertyResourceBundle (java.io.InputStream stream) throws java.io.IOException; | ||
// | Public Methods Overriding ResourceBundle | |
public Enumeration getKeys (); | ||
public Object handleGetObject (String key); | ||
} |
Hierarchy: Object-->ResourceBundle-->PropertyResourceBundle
Random | Java 1.0 | |
|
||
java.util | serializable PJ1.1 |
This class implements a pseudo-random number generator suitable for games and similar applications. If you need a cryptographic-strength source of pseudo-randomness, see java.security.SecureRandom. nextDouble() and nextFloat() return a value between 0.0 and 1.0. nextLong() and the no-argument version of nextInt() return long and int values distributed across the range of those data types. In Java 1.2, if you pass an argument to nextInt(), it returns a value between zero (inclusive) and the specified number (exclusive). nextGaussian() returns pseudo-random floating-point values with a Gaussian distribution; the mean of the values is 0.0 and the standard deviation is 1.0. nextBoolean() returns a pseudo-random boolean value, and nextBytes() fills in the specified byte array with pseudo-random bytes. You can use the setSeed() method or the optional constructor argument to initialize the pseudo-random number generator with some variable seed value other than the current time (the default) or with a constant to ensure a repeatable sequence of pseudo-randomness.
public class Random implements Serializable { | ||
// | Public Constructors | |
public Random (); | ||
public Random (long seed); | ||
// | Public Instance Methods | |
1.2 | public boolean nextBoolean (); | |
1.1 | public void nextBytes (byte[ ] bytes); | |
public double nextDouble (); | ||
public float nextFloat (); | ||
public double nextGaussian (); | synchronized | |
public int nextInt (); | ||
1.2 | public int nextInt (int n); | |
public long nextLong (); | ||
public void setSeed (long seed); | synchronized | |
// | Protected Instance Methods | |
protected int next (int bits); | synchronized | |
} |
Hierarchy: Object-->Random(Serializable)
Subclasses: java.security.SecureRandom
Passed To: java.math.BigInteger.BigInteger(), Collections.shuffle()
ResourceBundle | Java 1.1 | |
|
||
java.util | PJ1.1 |
This abstract class allows subclasses to define sets of localized resources that can then be dynamically loaded as needed by internationalized programs. Such resources may include user-visible text and images that appear in an application, as well as more complex things such as Menu objects. Use getBundle() to load a ResourceBundle subclass that is appropriate for the default or specified locale. Use getObject(), getString(), and getStringArray() to look up a named resource in a bundle. To define a bundle, provide implementations of handleGetObject() and getKeys(). It is often easier, however, to subclass ListResourceBundle or provide a Properties file that is used by PropertyResourceBundle. The name of any localized ResourceBundle class you define should include the locale language code, and, optionally, the locale country code.
public abstract class ResourceBundle { | ||
// | Public Constructors | |
public ResourceBundle (); | ||
// | Public Class Methods | |
public static final ResourceBundle getBundle (String baseName) throws MissingResourceException; | ||
public static final ResourceBundle getBundle (String baseName, Locale locale); | ||
public static ResourceBundle getBundle (String baseName, Locale locale, ClassLoader loader) throws MissingResourceException; | ||
// | Public Instance Methods | |
public abstract Enumeration getKeys (); | ||
1.2 | public Locale getLocale (); | |
public final Object getObject (String key) throws MissingResourceException; | ||
public final String getString (String key) throws MissingResourceException; | ||
public final String[ ] getStringArray (String key) throws MissingResourceException; | ||
// | Protected Instance Methods | |
protected abstract Object handleGetObject (String key) throws MissingResourceException; | ||
protected void setParent (ResourceBundle parent); | ||
// | Protected Instance Fields | |
protected ResourceBundle parent ; | ||
} |
Subclasses: ListResourceBundle, PropertyResourceBundle
Passed To: java.awt.ComponentOrientation.getOrientation(), java.awt.Window.applyResourceBundle(), ResourceBundle.setParent()
Returned By: ResourceBundle.getBundle()
Type Of: ResourceBundle.parent
Set | Java 1.2 | |
|
||
java.util | collection |
This interface represents an unordered Collection of objects that contains no duplicate elements. That is, a Set cannot contain two elements e1 and e2 where e1.equals(e2), and it can contain at most one null element. The Set interface defines the same methods as its superinterface, Collection. It constrains the add() and allAll() methods from adding duplicate elements to the Set.
An interface cannot specify constructors, but it is conventional that all implementations of Set provide at least two standard constructors: one that takes no arguments and creates an empty set, and a copy constructor that accepts a Collection object that specifies the initial contents of the new Set. This copy constructor must ensure that duplicate elements are not added to the Set, of course.
As with Collection, the Set methods that modify the contents of the set are optional, and implementations that do not support these methods simply throw java.lang.UnsupportedOperationException. See also Collection, List, Map, SortedSet, HashSet, and TreeSet.
public interface Set extends Collection { | ||
// | Public Instance Methods | |
public abstract boolean add (Object o); | ||
public abstract boolean addAll (Collection c); | ||
public abstract void clear (); | ||
public abstract boolean contains (Object o); | ||
public abstract boolean containsAll (Collection c); | ||
public abstract boolean equals (Object o); | ||
public abstract int hashCode (); | ||
public abstract boolean isEmpty (); | ||
public abstract Iterator iterator (); | ||
public abstract boolean remove (Object o); | ||
public abstract boolean removeAll (Collection c); | ||
public abstract boolean retainAll (Collection c); | ||
public abstract int size (); | ||
public abstract Object[ ] toArray (); | ||
public abstract Object[ ] toArray (Object[ ] a); | ||
} |
Hierarchy: (Set(Collection))
Implementations: AbstractSet, HashSet, SortedSet
Passed To: java.text.AttributedCharacterIterator.{getRunLimit(), getRunStart()}, Collections.{synchronizedSet(), unmodifiableSet()}
Returned By: Too many methods to list.
Type Of: Collections.EMPTY_SET
SimpleTimeZone | Java 1.1 | |
|
||
java.util | cloneable serializable PJ1.1 |
This concrete subclass of TimeZone is a simple implementation of that abstract class that is suitable for use in locales that use the Gregorian calendar. Programs do not normally need to instantiate this class directly; instead, they use one of the static factory methods of TimeZone to obtain a suitable TimeZone subclass. The only reason to instantiate this class directly is if you need to support a time zone with non-standard-daylight-savings-time rules. In that case, you can call setStartRule() and setEndRule() to specify the starting and ending dates of daylight-savings time for the time zone.
public class SimpleTimeZone extends TimeZone { | ||
// | Public Constructors | |
public SimpleTimeZone (int rawOffset, String ID); | ||
public SimpleTimeZone (int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime); | ||
public SimpleTimeZone (int rawOffset, String ID, int startMonth, int startDay, int startDayOfWeek, int startTime, int endMonth, int endDay, int endDayOfWeek, int endTime, int dstSavings); | ||
// | Public Instance Methods | |
1.2 | public int getDSTSavings (); | |
1.2 | public void setDSTSavings (int millisSavedDuringDST); | |
1.2 | public void setEndRule (int month, int dayOfMonth, int time); | |
public void setEndRule (int month, int dayOfWeekInMonth, int dayOfWeek, int time); | ||
1.2 | public void setEndRule (int month, int dayOfMonth, int dayOfWeek, int time, boolean after); | |
1.2 | public void setStartRule (int month, int dayOfMonth, int time); | |
public void setStartRule (int month, int dayOfWeekInMonth, int dayOfWeek, int time); | ||
1.2 | public void setStartRule (int month, int dayOfMonth, int dayOfWeek, int time, boolean after); | |
public void setStartYear (int year); | ||
// | Public Methods Overriding TimeZone | |
public Object clone (); | ||
public int getOffset (int era, int year, int month, int day, int dayOfWeek, int millis); | ||
public int getRawOffset (); | ||
1.2 | public boolean hasSameRules (TimeZone other); | |
public boolean inDaylightTime (java.util.Date date); | ||
public void setRawOffset (int offsetMillis); | ||
public boolean useDaylightTime (); | ||
// | Public Methods Overriding Object | |
public boolean equals (Object obj); | ||
public int hashCode (); | synchronized | |
public String toString (); | ||
} |
Hierarchy: Object-->TimeZone(Cloneable,Serializable)-->SimpleTimeZone
SortedMap | Java 1.2 | |
|
||
java.util | collection |
This interface represents a Map object that keeps its set of key objects in sorted order. As with Map, it is conventional that all implementations of this interface define a no-argument constructor to create an empty map and a copy constructor that accepts a Map object that specifies the initial contents of the SortedMap. Furthermore, when creating a SortedMap, there should be a way to specify a Comparator object to sort the key objects of the map. If no Comparator is specified, all key objects must implement the java.lang.Comparable interface so they can be sorted in their natural order. See also Map, TreeMap, and SortedSet.
The inherited keySet(), values(), and entrySet() methods return collections that can be iterated in the sorted order. firstKey() and lastKey() return the lowest and highest key values in the SortedMap. subMap() returns a SortedMap that contains only mappings for keys from (and including) the first specified key up to (but not including) the second specified key. headMap() returns a SortedMap that contains mappings whose keys are less than (but not equal to) the specified key. tailMap() returns a SortedMap that contains mappings whose keys are greater than or equal to the specified key. subMap(), headMap(), and tailMap() return SortedMap objects that are simply views of the original SortedMap; any changes in the original map are reflected in the returned map and vice versa.
public interface SortedMap extends Map { | ||
// | Public Instance Methods | |
public abstract Comparator comparator (); | ||
public abstract Object firstKey (); | ||
public abstract SortedMap headMap (Object toKey); | ||
public abstract Object lastKey (); | ||
public abstract SortedMap subMap (Object fromKey, Object toKey); | ||
public abstract SortedMap tailMap (Object fromKey); | ||
} |
Hierarchy: (SortedMap(Map))
Implementations: TreeMap
Passed To: Collections.{synchronizedSortedMap(), unmodifiableSortedMap()}, TreeMap.TreeMap()
Returned By: Collections.{synchronizedSortedMap(), unmodifiableSortedMap()}, SortedMap.{headMap(), subMap(), tailMap()}, TreeMap.{headMap(), subMap(), tailMap()}
SortedSet | Java 1.2 | |
|
||
java.util | collection |
This interface is a Set that sorts its elements and guarantees that its iterator() method returns an Iterator that enumerates the elements of the set in sorted order. As with the Set interface, it is conventional for all implementations of SortedSet to provide a no-argument constructor that creates an empty set and a copy constructor that expects a Collection object specifying the initial (unsorted) contents of the set. Furthermore, when creating a SortedSet, there should be a way to specify a Comparator object that compares and sorts the elements of the set. If no Comparator is specified, the elements of the set must all implement java.lang.Comparable so they can be sorted in their natural order. See also Set, TreeSet, and SortedMap.
SortedSet defines a few methods in addition to those it inherits from the Set interface. first() and last() return the lowest and highest objects in the set. headSet() returns all elements from the beginning of the set up to (but not including) the specified element. tailSet() returns all elements between (and including) the specified element and the end of the set. subSet() returns all elements of the set from (and including) the first specified element up to (but excluding) the second specified element. Note that all three methods return a SortedSet that is implemented as a view onto the original SortedSet. Changes in the original set are visible through the returned set and vice versa.
public interface SortedSet extends Set { | ||
// | Public Instance Methods | |
public abstract Comparator comparator (); | ||
public abstract Object first (); | ||
public abstract SortedSet headSet (Object toElement); | ||
public abstract Object last (); | ||
public abstract SortedSet subSet (Object fromElement, Object toElement); | ||
public abstract SortedSet tailSet (Object fromElement); | ||
} |
Hierarchy: (SortedSet(Set(Collection)))
Implementations: TreeSet
Passed To: Collections.{synchronizedSortedSet(), unmodifiableSortedSet()}, TreeSet.TreeSet()
Returned By: Collections.{synchronizedSortedSet(), unmodifiableSortedSet()}, SortedSet.{headSet(), subSet(), tailSet()}, TreeSet.{headSet(), subSet(), tailSet()}
Stack | Java 1.0 | |
|
||
java.util | cloneable serializable collection PJ1.1 |
This class implements a last-in-first-out (LIFO) stack of objects. push() puts an object on the top of the stack. pop() removes and returns the top object from the stack. peek() returns the top object without removing it. In Java 1.2, you can instead use a LinkedList as a stack.
public class Stack extends Vector { | ||
// | Public Constructors | |
public Stack (); | ||
// | Public Instance Methods | |
public boolean empty (); | ||
public Object peek (); | synchronized | |
public Object pop (); | synchronized | |
public Object push (Object item); | ||
public int search (Object o); | synchronized | |
} |
Hierarchy: Object-->AbstractCollection(Collection)-->AbstractList(java.util.List(Collection))-->Vector(Cloneable,java.util.List(Collection),Serializable)-->Stack
StringTokenizer | Java 1.0 | |
|
||
java.util | PJ1.1 |
When a StringTokenizer is instantiated with a String, it breaks the string up into tokens separated by any of the characters in the specified string of delimiters. (For example, words separated by space and tab characters are tokens.) The hasMoreTokens() and nextToken() methods obtain the tokens in order. countTokens() returns the number of tokens in the string. StringTokenizer implements the Enumeration interface, so you may also access the tokens with the familiar hasMoreElements() and nextElement() methods. When you create a StringTokenizer, you can specify a string of delimiter characters to use for the entire string, or you can rely on the default whitespace delimiters. You can also specify whether the delimiters themselves should be returned as tokens. Finally, you can optionally specify a new string of delimiter characters when you call nextToken().
public class StringTokenizer implements Enumeration { | ||
// | Public Constructors | |
public StringTokenizer (String str); | ||
public StringTokenizer (String str, String delim); | ||
public StringTokenizer (String str, String delim, boolean returnDelims); | ||
// | Public Instance Methods | |
public int countTokens (); | ||
public boolean hasMoreTokens (); | ||
public String nextToken (); | ||
public String nextToken (String delim); | ||
// | Methods Implementing Enumeration | |
public boolean hasMoreElements (); | ||
public Object nextElement (); | ||
} |
Hierarchy: Object-->StringTokenizer(Enumeration)
Timer | Java 1.3 Beta | |
|
||
java.util |
This class implements a timer: its methods allow you to schedule one or more runnable TimerTask objects to be executed (once or repetitively) by a background thread at a specified time in the future. You can create a timer with the Timer() constructor. The no-argument version of this constructor creates a regular non-daemon background thread, which means that the Java VM will not terminate while the timer thread is running. Pass true to the constructor if you want the background thread to be a daemon thread.
Once you have created a Timer, you can schedule TimerTask objects to be run in the future with the various schedule() and scheduleAtFixedRate() methods. To schedule a task for a single execution, use one of the two-argument schedule() methods and specify the desired execution time either as a number of milliseconds in the future or as an absolute Date. If the number of milliseconds is 0, or if the Date object represents a time already passed, the task is scheduled for immediate execution.
To schedule a repeating task, use one of the three-argument versions of schedule() or scheduleAtFixedRate(). These methods are passed an argument that specifies the time (either as a number of milliseconds or as a Date object) of the first execution of the task and another argument, period, that specifies the number of milliseconds between repeated executions of the task. The schedule() methods schedule the task for fixed-interval execution. That is, each execution is scheduled for period milliseconds after the previous execution ends. Use schedule() for tasks such as animation, where it is important to have a relatively constant interval between executions. The scheduleAtFixedRate() methods, on the other hand, schedule tasks for fixed-rate execution. That is, each repetition of the task is scheduled for period milliseconds after the previous execution begins. Use scheduleAtFixedRate() for tasks, such as updating a clock display, that must occur at specific absolute times rather than at fixed intervals.
A single Timer object can comfortably schedule many TimerTask objects. Note, however, that all tasks scheduled by a single Timer share a single thread. If you are scheduling many rapidly repeating tasks, or if some tasks take a long time to execute, other tasks may have their scheduled executions delayed.
When you are done with a Timer, call cancel() to stop its associated thread from running. This is particularly important when you are using a timer whose associated thread is not a daemon thread, because otherwise the timer thread can prevent the Java VM from exiting. To cancel the execution of a particular task, use the cancel() method of TimerTask.
public class Timer { | ||
// | Public Constructors | |
public Timer (); | ||
public Timer (boolean isDaemon); | ||
// | Public Instance Methods | |
public void cancel (); | ||
public void schedule (TimerTask task, long delay); | ||
public void schedule (TimerTask task, java.util.Date time); | ||
public void schedule (TimerTask task, java.util.Date firstTime, long period); | ||
public void schedule (TimerTask task, long delay, long period); | ||
public void scheduleAtFixedRate (TimerTask task, long delay, long period); | ||
public void scheduleAtFixedRate (TimerTask task, java.util.Date firstTime, long period); | ||
} |
TimerTask | Java 1.3 Beta | |
|
||
java.util | runnable |
This abstract Runnable class represents a task that is scheduled with a Timer object for one-time or repeated execution in the future. You can define a task by subclassing TimerTask and implementing the abstract run() method. Schedule the task for future execution by passing an instance of your subclass to one of the schedule() or scheduleAtFixedRate() methods of Timer. The Timer object will then invoke the run() method at the scheduled time or times.
Call cancel() to cancel the one-time or repeated execution of a TimerTask(). This method returns true if a pending execution was actually canceled. It returns false if the task has already been canceled, was never scheduled, or was scheduled for one-time execution and has already been executed. scheduledExecutionTime() returns the time in milliseconds at which the most recent execution of the TimerTask was scheduled to occur. When the host system is heavily loaded, the run() method may not be invoked exactly when scheduled. Some tasks may choose to do nothing if they are not invoked on time. The run() method can compare the return values of scheduledExecutionTime() and System.currentTimeMillis() to determine whether the current invocation is sufficiently timely.
public abstract class TimerTask implements Runnable { | ||
// | Protected Constructors | |
public TimerTask (); | ||
// | Public Instance Methods | |
public boolean cancel (); | ||
public long scheduledExecutionTime (); | ||
// | Methods Implementing Runnable | |
public abstract void run (); | ||
} |
Hierarchy: Object-->TimerTask(Runnable)
Passed To: java.util.Timer.{schedule(), scheduleAtFixedRate()}
TimeZone | Java 1.1 | |
|
||
java.util | cloneable serializable PJ1.1 |
The TimeZone class represents a time zone; it is used with the Calendar and DateFormat classes. As an abstract class, TimeZone cannot be directly instantiated. Instead, you should call the static getDefault() method to obtain a TimeZone object that represents the time zone inherited from the host operating system. Or you can call the static getTimeZone() method with the name of the desired zone. You can obtain a list of the supported time-zone names by calling the static getAvailableIDs() method.
Once you have a TimeZone object, you can call inDaylightTime() to determine whether, for a given Date, daylight-savings time is in effect for that time zone. Call getID() to obtain the name of the time zone. Call getOffset() for a given date to determine the number of milliseconds to add to GMT to convert to the time zone.
public abstract class TimeZone implements Cloneable, Serializable { | ||
// | Public Constructors | |
public TimeZone (); | ||
// | Public Constants | |
1.2 | public static final int LONG ; | =1 |
1.2 | public static final int SHORT ; | =0 |
// | Public Class Methods | |
public static String[ ] getAvailableIDs (); | synchronized | |
public static String[ ] getAvailableIDs (int rawOffset); | synchronized | |
public static TimeZone getDefault (); | synchronized | |
public static TimeZone getTimeZone (String ID); | synchronized | |
public static void setDefault (TimeZone zone); | synchronized | |
// | Property Accessor Methods (by property name) | |
1.2 | public final String getDisplayName (); | |
1.2 | public final String getDisplayName (Locale locale); | |
1.2 | public final String getDisplayName (boolean daylight, int style); | |
1.2 | public String getDisplayName (boolean daylight, int style, Locale locale); | |
public String getID (); | ||
public void setID (String ID); | ||
public abstract int getRawOffset (); | ||
public abstract void setRawOffset (int offsetMillis); | ||
// | Public Instance Methods | |
public abstract int getOffset (int era, int year, int month, int day, int dayOfWeek, int milliseconds); | ||
1.2 | public boolean hasSameRules (TimeZone other); | |
public abstract boolean inDaylightTime (java.util.Date date); | ||
public abstract boolean useDaylightTime (); | ||
// | Public Methods Overriding Object | |
public Object clone (); | ||
} |
Hierarchy: Object-->TimeZone(Cloneable,Serializable)
Subclasses: SimpleTimeZone
Passed To: java.text.DateFormat.setTimeZone(), Calendar.{Calendar(), getInstance(), setTimeZone()}, GregorianCalendar.GregorianCalendar(), SimpleTimeZone.hasSameRules(), TimeZone.{hasSameRules(), setDefault()}
Returned By: java.text.DateFormat.getTimeZone(), Calendar.getTimeZone(), TimeZone.{getDefault(), getTimeZone()}
TooManyListenersException | Java 1.1 | |
|
||
java.util | serializable checked PJ1.1 |
Signals that an AWT component, JavaBeans component, or Swing component can have only one EventListener object registered for some specific type of event. That is, it signals that a particular event is a unicast event rather than a multicast event. This exception type serves a formal purpose in the Java event model; its presence in the throws clause of an EventListener registration method (even if the method never actually throws the exception) signals that an event is a unicast event.
public class TooManyListenersException extends Exception { | ||
// | Public Constructors | |
public TooManyListenersException (); | ||
public TooManyListenersException (String s); | ||
} |
Hierarchy: Object-->Throwable(Serializable)-->Exception-->TooManyListenersException
Thrown By: java.awt.dnd.DragGestureRecognizer.addDragGestureListener(), java.awt.dnd.DragSourceContext.addDragSourceListener(), java.awt.dnd.DropTarget.addDropTargetListener(), java.beans.beancontext.BeanContextServices.getService(), java.beans.beancontext.BeanContextServicesSupport.getService()
TreeMap | Java 1.2 | |
|
||
java.util | cloneable serializable collection |
This class implements the SortedMap interface using an internal Red-Black tree data structure and guarantees that the keys and values of the mapping can be enumerated in ascending order of keys. TreeMap supports all optional Map methods. The objects used as keys in a TreeMap must all be mutually Comparable, or an appropriate Comparator must be provided when the TreeMap is created. Because TreeMap is based on a binary tree data structure, the get(), put(), remove(), and containsKey() methods operate in relatively efficient logarithmic time. If you do not need the sorting capability of TreeMap, however, use HashMap instead, as it is even more efficient. See Map and SortedMap for details on the methods of TreeMap. See also the related TreeSet class.
In order for a TreeMap to work correctly, the comparison method from the Comparable or Comparator interface must be consistent with the equals() method. That is, the equals() method must compare two objects as equal if and only if the comparison method also indicates those two objects are equal.
The methods of TreeMap are not synchronized. If you are working in a multithreaded environment, you must explicitly synchronize all code that modifies the TreeMap, or obtain a synchronized wrapper with Collections.synchronizedMap().
public class TreeMap extends AbstractMap implements Cloneable, Serializable, SortedMap { | ||
// | Public Constructors | |
public TreeMap (); | ||
public TreeMap (Map m); | ||
public TreeMap (SortedMap m); | ||
public TreeMap (Comparator c); | ||
// | Methods Implementing Map | |
public void clear (); | ||
public boolean containsKey (Object key); | ||
public boolean containsValue (Object value); | ||
public Set entrySet (); | ||
public Object get (Object key); | ||
public Set keySet (); | ||
public Object put (Object key, Object value); | ||
public void putAll (Map map); | ||
public Object remove (Object key); | ||
public int size (); | ||
public Collection values (); | ||
// | Methods Implementing SortedMap | |
public Comparator comparator (); | ||
public Object firstKey (); | ||
public SortedMap headMap (Object toKey); | ||
public Object lastKey (); | ||
public SortedMap subMap (Object fromKey, Object toKey); | ||
public SortedMap tailMap (Object fromKey); | ||
// | Public Methods Overriding Object | |
public Object clone (); | ||
} |
Hierarchy: Object-->AbstractMap(Map)-->TreeMap(Cloneable,Serializable,SortedMap(Map))
TreeSet | Java 1.2 | |
|
||
java.util | cloneable serializable collection |
This class implements SortedSet, provides support for all optional methods, and guarantees that the elements of the set can be enumerated in ascending order. In order to be sorted, the elements of the set must all be mutually Comparable objects, or they must all be compatible with a Comparator object that is specified when the TreeSet is created. TreeSet is implemented on top of a TreeMap, so its add(), remove(), and contains() methods all operate in relatively efficient logarithmic time. If you do not need the sorting capability of TreeSet, however, use HashSet instead, as it is significantly more efficient. See Set, SortedSet, and Collection for details on the methods of TreeSet.
In order for a TreeSet to operate correctly, the Comparable or Comparator comparison method must be consistent with the equals() method. That is, the equals() method must compare two objects as equal if and only if the comparison method also indicates those two objects are equal.
The methods of TreeSet are not synchronized. If you are working in a multithreaded environment, you must explicitly synchronize code that modifies the contents of the set,x or obtain a synchronized wrapper with Collections.synchronizedSet().
public class TreeSet extends AbstractSet implements Cloneable, Serializable, SortedSet { | ||
// | Public Constructors | |
public TreeSet (); | ||
public TreeSet (SortedSet s); | ||
public TreeSet (Comparator c); | ||
public TreeSet (Collection c); | ||
// | Methods Implementing Set | |
public boolean add (Object o); | ||
public boolean addAll (Collection c); | ||
public void clear (); | ||
public boolean contains (Object o); | ||
public boolean isEmpty (); | default:true | |
public Iterator iterator (); | ||
public boolean remove (Object o); | ||
public int size (); | ||
// | Methods Implementing SortedSet | |
public Comparator comparator (); | ||
public Object first (); | ||
public SortedSet headSet (Object toElement); | ||
public Object last (); | ||
public SortedSet subSet (Object fromElement, Object toElement); | ||
public SortedSet tailSet (Object fromElement); | ||
// | Public Methods Overriding Object | |
public Object clone (); | ||
} |
Hierarchy: Object-->AbstractCollection(Collection)-->AbstractSet(Set(Collection))-->TreeSet(Cloneable,Serializable,SortedSet(Set(Collection)))
Vector | Java 1.0 | |
|
||
java.util | cloneable serializable collection PJ1.1 |
This class implements an ordered collection--essentially an array--of objects that can grow or shrink as necessary. Vector is useful when you need to keep track of a number of objects, but do not know in advance how many there will be. Use setElementAt() to set the object at a given index of a Vector. Use elementAt() to retrieve the object stored at a specified index. Note that you typically must cast the Object returned by elementAt() to the desired type. Call add() to append an object to the end of the Vector or to insert an object at any specified position. Use removeElementAt() to delete the element at a specified index or removeElement() to remove a specified object from the vector. size() returns the number of objects currently in the Vector. elements() returns an Enumeration that allows you to iterate through those objects. capacity() is not the same as size(); it returns the maximum number of objects a Vector can hold before its internal storage must be resized. Vector automatically resizes its internal storage for you, but if you know in advance how many objects a Vector will contain, you can increase its efficiency by pre-allocating this many elements with ensureCapacity().
Vector has been part of the java.util package since Java 1.0, but in Java 1.2 it has been enhanced to implement the List interface. List defines new names for many of the methods already present in Vector; see List for details on those methods. Vector is quite similar to the ArrayList class, except that the methods of Vector are synchronized, which makes them thread-safe but increases the overhead of calling them. If you need thread safety or need to be compatible with Java 1.0 or Java 1.1, use Vector; otherwise, use ArrayList.
public class Vector extends AbstractList, implements Cloneable, java.util.List, Serializable { | ||
// | Public Constructors | |
public Vector (); | ||
1.2 | public Vector (Collection c); | |
public Vector (int initialCapacity); | ||
public Vector (int initialCapacity, int capacityIncrement); | ||
// | Public Instance Methods | |
public void addElement (Object obj); | synchronized | |
public int capacity (); | ||
public void copyInto (Object[ ] anArray); | synchronized | |
public Object elementAt (int index); | synchronized | |
public Enumeration elements (); | ||
public void ensureCapacity (int minCapacity); | synchronized | |
public Object firstElement (); | synchronized | |
public int indexOf (Object elem, int index); | synchronized | |
public void insertElementAt (Object obj, int index); | synchronized | |
public Object lastElement (); | synchronized | |
public int lastIndexOf (Object elem, int index); | synchronized | |
public void removeAllElements (); | synchronized | |
public boolean removeElement (Object obj); | synchronized | |
public void removeElementAt (int index); | synchronized | |
public void setElementAt (Object obj, int index); | synchronized | |
public void setSize (int newSize); | synchronized | |
public void trimToSize (); | synchronized | |
// | Methods Implementing List | |
1.2 | public boolean add (Object o); | synchronized |
1.2 | public void add (int index, Object element); | |
1.2 | public boolean addAll (Collection c); | synchronized |
1.2 | public boolean addAll (int index, Collection c); | synchronized |
1.2 | public void clear (); | |
public boolean contains (Object elem); | ||
1.2 | public boolean containsAll (Collection c); | synchronized |
1.2 | public boolean equals (Object o); | synchronized |
1.2 | public Object get (int index); | synchronized |
1.2 | public int hashCode (); | synchronized |
public int indexOf (Object elem); | ||
public boolean isEmpty (); | default:true | |
public int lastIndexOf (Object elem); | ||
1.2 | public boolean remove (Object o); | |
1.2 | public Object remove (int index); | synchronized |
1.2 | public boolean removeAll (Collection c); | synchronized |
1.2 | public boolean retainAll (Collection c); | synchronized |
1.2 | public Object set (int index, Object element); | synchronized |
public int size (); | ||
1.2 | public java.util.List subList (int fromIndex, int toIndex); | |
1.2 | public Object[ ] toArray (); | synchronized |
1.2 | public Object[ ] toArray (Object[ ] a); | synchronized |
// | Protected Methods Overriding AbstractList | |
1.2 | protected void removeRange (int fromIndex, int toIndex); | |
// | Public Methods Overriding AbstractCollection | |
public String toString (); | synchronized | |
// | Public Methods Overriding Object | |
public Object clone (); | synchronized | |
// | Protected Instance Fields | |
protected int capacityIncrement ; | ||
protected int elementCount ; | ||
protected Object[ ] elementData ; | ||
} |
Hierarchy: Object-->AbstractCollection(Collection)-->AbstractList(java.util.List(Collection))-->Vector(Cloneable,java.util.List(Collection),Serializable)
Subclasses: Stack
Passed To: Too many methods to list.
Returned By: java.awt.image.BufferedImage.getSources(), java.awt.image.RenderedImage.getSources(), java.awt.image.renderable.ParameterBlock.{getParameters(), getSources()}, java.awt.image.renderable.RenderableImage.getSources(), java.awt.image.renderable.RenderableImageOp.getSources(), javax.swing.table.DefaultTableModel.{convertToVector(), getDataVector()}, javax.swing.text.GapContent.getPositionsInRange(), javax.swing.text.StringContent.getPositionsInRange()
Type Of: Too many fields to list.
WeakHashMap | Java 1.2 | |
|
||
java.util | collection |
This class implements Map using an internal hashtable. It is similar in features and performance to HashMap, except that it uses the capabilities of the java.lang.ref package, so that the key-to-value mappings it maintains do not prevent the key objects from being reclaimed by the garbage collector. When there are no more references to a key object except for the weak reference maintained by the WeakHashMap, the garbage collector reclaims the object, and the WeakHashMap deletes the mapping between the reclaimed key and its associated value. If there are no references to the value object except for the one maintained by the WeakHashMap, the value object also becomes available for garbage collection. Thus, you can use a WeakHashMap to associate an auxiliary value with an object without preventing either the object (the key) or the auxiliary value from being reclaimed. See HashMap for a discussion of the implementation features of this class. See Map for a description of the methods it defines.
WeakHashMap is primarily useful with objects whose equals() methods use the == operator for comparison. It is less useful with key objects of type String, for example, because there can be multiple String objects that are equal to one another and, even if the original key value has been reclaimed by the garbage collector, it is always possible to pass a String with the same value to the get() method.
public class WeakHashMap extends AbstractMap implements Map { | ||
// | Public Constructors | |
public WeakHashMap (); | ||
1.3 | public WeakHashMap (Map t); | |
public WeakHashMap (int initialCapacity); | ||
public WeakHashMap (int initialCapacity, float loadFactor); | ||
// | Methods Implementing Map | |
public void clear (); | ||
public boolean containsKey (Object key); | ||
public Set entrySet (); | ||
public Object get (Object key); | ||
public boolean isEmpty (); | default:true | |
public Object put (Object key, Object value); | ||
public Object remove (Object key); | ||
public int size (); | ||
} |
Hierarchy: Object-->AbstractMap(Map)-->WeakHashMap(Map)
Copyright © 2001 O'Reilly & Associates. All rights reserved.
This HTML Help has been published using the chm2web software. |