Click here to watch in Youtube :
https://www.youtube.com/watch?v=I539_03WtO8&list=UUhwKlOVR041tngjerWxVccw
HashMapExample.java
Output
https://www.youtube.com/watch?v=I539_03WtO8&list=UUhwKlOVR041tngjerWxVccw
HashMapExample.java
import java.util.HashMap; /* * Example of clear() method. */ public class HashMapExample { public static void main(String[] args) { HashMap<Integer, String> hashMap = new HashMap<Integer, String>(); hashMap.put(1, "Apple"); hashMap.put(3, "Cat"); hashMap.put(2, "Ball"); System.out.println("hashMap : " + hashMap + "\n"); /* * Removes all of the mappings from this map. The map will be empty * after this call returns. */ hashMap.clear(); System.out.println("hashMap : " + hashMap); } }
hashMap : {1=Apple, 2=Ball, 3=Cat} hashMap : {}
https://sites.google.com/site/javaee4321/java-collections/HashMapDemoClear.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment