当前页面: 开发资料首页 → Java 专题 → java的Collections框架的理解
摘要: java的Collections框架的理解
public interface java.util.Map {
//Altering Methods
public Object put(Object key, Object value);
public Object remove(Object key);
public void putAll(java.util.Map);
public void clear();
//Querying Methods
public Object get(Object key);
public int size();
public boolean isEmpty();
public boolean containsKey(Object);
public boolean containsValue(Object);
public boolean equals(Object);
//Viewing Methods
public java.util.Set keySet(); //Gets keys
public java.util.Collection values(); //Gets values
public java.util.Set entrySet(); //Gets mappings
public static interface java.util.Map.Entry { //a map-entry (single key/value pair)
public Object getKey(); //returns current entry key
public Object getValue(); //returns current entry value
public Object setValue(Object value);
public boolean equals(Object);
public int hashCode();
}
}
public class java.util.Hashtable extends Dictionary implements Cloneable, Map, Serializable {
//Hashtable constructors
//construct a default Hashtable with default capacity and load of 0.75
public Hashtable();
//construct a Hashtable with passed capacity and default load of 0.75
public Hashtable (int initialCapacity);
//construct Hashtable with passed capacity and load
public Hashtable(int initialCapacity, float load);
//construct Hashtable with passed mapping
public Hashtable(Map);
//Hashtable specific methods
//checks if Object is in Hashtable
public boolean contains(Object);
//returns Enumeration of elements in Hashtable
public Enumeration elements();
//returns Enumeration of keys in hashtable
public Enumeration keys();
//creates shallow copy of Hashtable(structure copied, but not key/values)
public Object clone();
//prints out key/value pairs of Hashtable elements
public String toString();
//reorganizes all elements in Hashtable, and increases Hashtable capacity
protected void rehash();
//get Value from passed in key
public Object get(Object);
//insert key/value pair
public Object put(Object key, Object value);
}
private static class Entry implements Map.Entry{
int hashCode;
Object key;
Object value;
Entry next;
Entry(int hashCode,Object key,Object value,Entry next){
This.hashCode=hashCode;
This.key=key;
This.value=value;
This.next=next;
}
public Object getKey(){
return key;
}
public Object getValue(){
return value;
}
public Object setValue(Object value){
Object oldValue=this.value;
This.value=value;
Return oldValue;
}
}