求一个java hashtable存入10条记录,内容随便定义,在把10条记录打印出来 最好附加些解释 新手 水平有限!
1个回答
展开全部
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
public class A {
public static void main(String[] args) {
Hashtable<String, Integer> numbers = new Hashtable<String, Integer>();
numbers.put("one", new Integer(1));
numbers.put("衡世two", new Integer(25));
numbers.put("three", new Integer(32));
numbers.put("abc", new Integer(47));
numbers.put("hello", new Integer(5));
numbers.put("apple", new Integer(63));
numbers.put("xyz", new Integer(7));
numbers.put("咐清肢pear", new Integer(8));
numbers.put("class", new Integer(99));
numbers.put("java"正态, new Integer(125));
Iterator<Map.Entry<String, Integer>> ite = numbers.entrySet().iterator();
while(ite.hasNext()){
Map.Entry<String, Integer> entry = ite.next();
System.out.println(entry.getKey() + "\t" + entry.getValue().toString());
}
}
}
import java.util.Iterator;
import java.util.Map;
public class A {
public static void main(String[] args) {
Hashtable<String, Integer> numbers = new Hashtable<String, Integer>();
numbers.put("one", new Integer(1));
numbers.put("衡世two", new Integer(25));
numbers.put("three", new Integer(32));
numbers.put("abc", new Integer(47));
numbers.put("hello", new Integer(5));
numbers.put("apple", new Integer(63));
numbers.put("xyz", new Integer(7));
numbers.put("咐清肢pear", new Integer(8));
numbers.put("class", new Integer(99));
numbers.put("java"正态, new Integer(125));
Iterator<Map.Entry<String, Integer>> ite = numbers.entrySet().iterator();
while(ite.hasNext()){
Map.Entry<String, Integer> entry = ite.next();
System.out.println(entry.getKey() + "\t" + entry.getValue().toString());
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询