When Do You Choose Hashmaps In Java Code Example

Snippet 1

  import java.util.HashMap;
//Within a class
//You can do new HashMap();, but you don't need to
HashMap examplehashmap=new HashMap<>();
//put in values
 examplehashmap.put(5, "example");
//get value
//returns "example" 

Snippet 2

  import java.util.HashMap;

HashMap key = new HashMap();
key.put("abcd", 5);

System.out.println(key.get(5)); //prints out abcd 

Copyright © Code Fetcher 2020




Leave a comment

Your email address will not be published. Required fields are marked *