Thursday, March 14, 2019

Collections.unmodifiableMap(map) Example

package com.javainuse;
import java.util.*;
public class JavaStringBuffer {
public static  <T> void main(String[] args) {

             Map<Integer, String> map = new HashMap<>();
             map.put(1, "one");
             map.put(2, "two");
             System.out.println("Initial Unmodifiable Map: "+map);
             Map<Integer, String> map2 = Collections.unmodifiableMap(map);
             map2.put(3, "three");
             System.out.println(map);

}
}

No comments:

Post a Comment