package javastudy; import java.util.HashMap; import java.util.Map; public class TestMap { public static void main(String [] args ){ Map<String, String> map = new HashMap<String, String>(); map.put(String.valueOf(System.nanoTime())+"a", "1"); map.put(String.valueOf(System.nanoTime())+"a", "2"); map.put(String.valueOf(System.nanoTime())+"a", "3"); for (Map.Entry<String, String> entry : map.entrySet()){ System.out.print("key:"+entry.getKey()) ; System.out.println(" value:"+entry.getValue()); } System.out.println("keys: "+map.keySet()); System.out.println("values: "+map.values()); } }
结果
key:33869093351437a value:2
key:33869093363103a value:3
key:33869093271646a value:1
keys: [33869093351437a, 33869093363103a, 33869093271646a]
values: [2, 3, 1]
结论:
key--->set 不可有重复,输出的结果顺序有一定的随机性。
value-->collection