Java数据结构
枚举(Enumerration)
package java学习.数据结构;
import java.util.Vector;
import java.util.Enumeration;
public class EnumerationTester {
/*
枚举对象days
*/
public static void main(String[] args) {
Enumeration days;
Vector dagNames = new Vector();
dagNames.add("Sunday");
dagNames.add("Monday");
dagNames.add("Tuesday");
dagNames.add(" ");
dagNames.add("Wednesday");
dagNames.add("Thursday");
dagNames.add("Friday");
dagNames.add("Saturday");
days = dagNames.elements();
while (days.hasMoreElements()){
/**
* hasMoreElements()测试此枚举是否包含更多的元素
* nextElement()如果此枚举对象至少还有一个可提供元素,则返回此枚举的下一元素
*/
System.out.println(days.nextElement());
}
}
}
位集合(Bitset)
package java学习.数据结构;
import java.util.BitSet;
public class BitSetDemo {
/**
*
*/
public static void main(String[] args) {
BitSet bits1 = new BitSet(16);
BitSet bits2 = new BitSet(16);
for (int i =0;i<16;i++){
if (i%2==0)
bits1.set(i);
if ((i%5)!=0)
bits2.set(i);
}
System.out.println("Initial pattern in bits1:");
System.out.println(bits1);
System.out.println("\nInitial pattern in bits2:");
System.out.println(bits2);
//AND BITS
bits2.and(bits1);
System.out.println(" bits2 and bits1:");
System.out.println(bits2);
//OR BITS
bits2.or(bits1);
System.out.println(" bits2 or bits1:");
System.out.println(bits2);
//XOR BITS
bits2.xor(bits1);
System.out.println(" bits2 xor bits1:");
System.out.println(bits2);
}
}
向量(Vector)
package java学习.数据结构;
import java.util.*;
public class VectorDemo {
public static void main(String args[]) {
// initial size is 3, increment is 2
Vector v = new Vector(3, 2);
System.out.println("Initial size: " + v.size());
System.out.println("Initial capacity: " + v.capacity());
v.addElement(new Integer(1));
v.addElement(new Integer(2));
v.addElement(new Integer(3));
v.addElement(new Integer(4));
System.out.println("Capacity after four additions: " + v.capacity());
v.addElement(new Double(5.45));
System.out.println("Current capacity: " + v.capacity());
v.addElement(new Double(6.08));
v.addElement(new Integer(7));
System.out.println("Current capacity: " + v.capacity());
v.addElement(new Float(9.4));
v.addElement(new Integer(10));
System.out.println("Current capacity: " + v.capacity());
v.addElement(new Integer(11));
v.addElement(new Integer(12));
System.out.println("First element: " + (Integer)v.firstElement());
System.out.println("Last element: " + (Integer)v.lastElement());
if(v.contains(new Integer(3)))
System.out.println("Vector contains 3.");
// enumerate the elements in the vector.
Enumeration vEnum = v.elements();
System.out.println("\nElements in vector:");
while(vEnum.hasMoreElements())
System.out.print(vEnum.nextElement() + " ");
System.out.println();
}
}
栈(stack)
字典(dictionary)
哈希表(hashtable)
属性(properties)