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 :: javafx load image from resources 
Java :: what to do in minecraft 
Java :: java icon to image 
Java :: java font bold italic 
Java :: java in 5 minutes 
Java :: get image from resourcestream javafx 
Java :: android cella 20*20 java 
Java :: java 8 list to map with occurrences 
Java :: exitonclose swing 
Java :: java read from connection even if 404 
Sql :: PROSYS SQL BKP 
Sql :: uninstall mysql ubuntu 
Sql :: service postgres status 
Sql :: oracle get table schema 
Sql :: find duplicates mysql column 
Sql :: finding last created table mysql 
Sql :: sql server conection string 
Sql :: wilayah indonesia database 
Sql :: force drop all tables postgres 
Sql :: cast string to datetime mysql 
Sql :: mysql get first x characters 
Sql :: OSError: mysql_config not found 
Sql :: oracle all_source package body 
Sql :: sql auto update dupdated_at 
Sql :: oracle check table lock 
Sql :: restart mysql server ubuntu 
Sql :: postgresql convert text to float 
Sql :: convert epoch to date in sql server 
Sql :: psql lst trigger 
Sql :: mysql remove last empty newline 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =