- package org.niit.File;
- import java.util.HashMap;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.Set;
- import java.util.Map.Entry;
- import org.junit.Test;
- public class Test1 {
- @Test
- public void test() {
- Map<Character, Integer> map = new HashMap<Character, Integer>();
- map.put('a', 1);
- map.put('b', 2);
- map.put('c', 3);
- StringBuffer sb = new StringBuffer();
- Set<Entry<Character, Integer>> entry = map.entrySet();
- Iterator<Entry<Character, Integer>> ite = entry.iterator();
- while (ite.hasNext()) {
- Entry<Character, Integer> ent = ite.next();
- Character cha = ent.getKey();
- Integer i = ent.getValue();
- sb.append(cha + "(" + i + ")");
- }
- System.out.println(sb);
- }
- }
复制代码 |