temp=CustomerMaker.quickPassQueue.get(0);//获得首元素
CustomerMaker.quickPassQueue.remove(0);//删除首元素
quickPassQueue.add();在末尾添加元素
----演示程序-----
import java.util.*;
import java.io.*;
public class test
{
Vector v = new Vector();
public void testMethod(){
v.add("a");
v.add("b");
v.add("c");
System.out.println("\n原来的vecotr");
for(int i=0;i<v.size();i++){
System.out.println("\n"+" index is: "+ i + " element is: " +v.get(i));
}
v.remove(0);
System.out.println("\n去掉一个vector中第一个元素");
for(int i=0;i<v.size();i++){
System.out.println("\n"+" index is: "+ i + " element is: " +v.get(i));
}
}
public static void main(String[] args)
{
test t = new test();
t.testMethod();
System.out.println("Hello World!");
}
}
-----------------排序程序------------------------------
import java.util.*;
class MyCompare implements Comparator //实现Comparator,定义自己的比较方法
{
public int compare(Object o1, Object o2) {
Elem e1=(Elem)o1;
Elem e2=(Elem)o2;
if(e1.get() > e2.get())//这样比较是降序,如果把-1改成1就是升序.
{
return -1;
}
else if(e1.get()<e2.get())
{
return 1;
}
else
{
return 0;
}
}
}
class Elem {
private int iVal;
public Elem(int i) {
this.iVal = i;
}
public int get() {
return this.iVal;
}
}
public class Vector1 {
public static void main(String[] args) {
List v = new Vector();
v.add(new Elem(1));
v.add(new Elem(22));
v.add(new Elem(3));
v.add(new Elem(14));
Comparator ct = new MyCompare();
Collections.sort(v, ct);
for (int i = 0; i < v.size(); i++)
System.out.println(((Elem) v.get(i)).get());
}
}
posted on 2010-01-26 01:48
luis 阅读(6192)
评论(0) 编辑 收藏 引用 所属分类:
转载 、
Java笔记