HashMap中的强大参考

我试图理解强引用和弱引用, 借助WeakHashMap,我们可以轻松实现目标,但是如何在HashMap中实现呢? 当我使用以下代码时,String s3不是垃圾回收,为什么呢?

HashMap<String,String> wh=new HashMap<String,String>();
String s1=new String("Google");
String s2=new String("Microsoft");
String s3=new String("Apple");
wh.put(s1, "Search Engine");
wh.put(s2, "OS");
wh.put(s3, "Mac");
System.out.println(wh);
//s3=null;
WeakReference<String> wf=new WeakReference<>(s3);
s3=null;
System.gc();
System.out.println(wh); 



// Output-{Google=Search Engine, Apple=Mac, Microsoft=OS}

当我使用WeakHashMap做同样的事情时,它可以正常工作。

WeakHashMap<String, String> wh = new WeakHashMap<String, String>();
String s1 = new String("Google");
String s2 = new String("Microsoft");
String s3 = new String("Apple");
wh.put(s1, "Search Engine");
wh.put(s2, "OS");
wh.put(s3, "Mac");
System.out.println(wh);
s3 = null;
System.gc();
System.out.println(wh);