java数据结构

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值