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 :: x = x + y; in java 
Java :: Leap year or not program in java using if-else 
Java :: input 3 int 1 line in java 
Java :: what is java steam 
Java :: public class extends implements java 
Java :: /bin/sh 1 java not found docker 
Java :: ejercicios resueltos de python codeskulptor 
Java :: java forcing user to input int 
Java :: why does the ribbon dependency crush my app 
Java :: how to create simple java bean class for login page in eclipse 
Sql :: search text in all sql server stored procedure 
Sql :: sql server reset identity 
Sql :: mysql status 
Sql :: continue in sql 
Sql :: safe update mode in mysql 
Sql :: mysql how to reset primary key 
Sql :: return names of columns in table sql 
Sql :: mysql workbench download for iinux mint 19.3 
Sql :: drop all table postgresql 
Sql :: postgresql Insufficient privilege: 7 ERROR: permission denied for table 
Sql :: get the next auto_increment value mysql 
Sql :: rename column oracle 
Sql :: oracle search source code 
Sql :: rename column postgres 
Sql :: postgres change owner of schema 
Sql :: tsql update datetime 
Sql :: grant lock tables privilege mysql 
Sql :: oracle create schema 
Sql :: postgresql alter column nullable 
Sql :: drop column if exists sql server 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =