Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Map;
import java.util.WeakHashMap;

public class Main {
    public static void main(String[] args) {
        WeakHashMap<String, String> weakHashMapOne = new WeakHashMap<String, String>();
        WeakHashMap<String, String> weakHashMapTwo = new WeakHashMap<String, String>();

        System.out.println("Populating two Maps");

        weakHashMapOne.put("1", "first");
        weakHashMapOne.put("2", "two");
        weakHashMapOne.put("3", "from java2s.com");

        weakHashMapTwo.put("1", "1st");
        weakHashMapTwo.put("2", "2nd");
        weakHashMapTwo.put("3", "3rd");

        // checking Map
        System.out.println("Before - Map 1: " + weakHashMapOne);
        System.out.println("Before - Map 2: " + weakHashMapTwo);

        // putting map 2 into map1
        weakHashMapOne.putAll(weakHashMapTwo);

        System.out.println("After - Map 1: " + weakHashMapOne);
        System.out.println("After - Map 2: " + weakHashMapTwo);
    }
}