HashSet用法实例
在hashset中存入字符并输出
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Administrator
*/
public class HashTest {
public static void main(String[] args){
Set words = new HashSet<String>();
long totaltime = 0;
Scanner in =new Scanner(System.in);
while(in.hasNext()){
String word =in.next();
if (word.equals("exit")) {
break;
}
long callTime =System.currentTimeMillis();
words.add(word);
callTime =System.currentTimeMillis()-callTime;
totaltime+=callTime;
}
System.out.println("///////////////////////////////////////");
Iterator<String> it=words.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
System.out.println("Time:"+totaltime);
}
}
posted on 2010-10-30 11:50 sail out to sea 阅读(592) 评论(0) 编辑 收藏 举报