Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Java Hashmap Access Elements

import java.util.*;  
public class hashmapeg3{  
 public static void main(String args[]){  
   HashMap<Integer,String> map=new HashMap<Integer,String>();//Creating HashMap    
   map.put(1,"Cat");  //Put elements in Map  
   map.put(2,"Dog");    
   map.put(3,"Markhor");   
   map.put(4,"Peacock");   
       
   System.out.println("HashMap after put(): ");  
   for(Map.Entry m : map.entrySet()){    
    System.out.println(m.getKey()+" "+m.getValue());    
   }  
       // get() method to get value
    String value = map.get(1);
    System.out.println("Value at index 1: " + value);
}  
}
Comment

Access HashMap Elements

import java.util.HashMap;

class Main {
  public static void main(String[] args) {

    HashMap<Integer, String> languages = new HashMap<>();
    languages.put(1, "Java");
    languages.put(2, "Python");
    languages.put(3, "JavaScript");
    System.out.println("HashMap: " + languages);

    // get() method to get value
    String value = languages.get(1);
    System.out.println("Value at index 1: " + value);
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: write json file java 
Java :: sum of arraylist java 8 
Java :: Fibonacci Series Program. in java 
Java :: thymeleaf string not equal 
Java :: sort list of string lexicographically java 
Java :: how to convert bitmap to uri in android 
Java :: i have AdoptOpenJDK 8 but java --version gettinbg Unrecognized option: --version Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit. 
Java :: How to perform breadth first search through a binary tree, in Java? 
Java :: java for each 
Java :: get absolute path from relative java 
Java :: full screen dialog android 
Java :: java random guid 
Java :: how to convert string to boolean in java 
Java :: binding fragment android 
Java :: java random word from list 
Java :: how to iterate a queue in java 
Java :: java check if enum contains value 
Java :: how to read input in java 
Java :: counting nodes in binary search tree 
Java :: bubble sort for java ArrayList 
Java :: bootstrap 4 modal get event related target 
Java :: how to import math lib in java 
Java :: spring boot docker 
Java :: literals in java 
Java :: mobile number validation to edittext in android 
Java :: java remove duplicates 
Java :: java gridpane background color 
Java :: image cropper implementation 
Java :: java check if number is in range 
Java :: java while loop example 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =