Sunday, 18 December 2022

Java Collections - MAP

  A) HASHMAP

 Write a program using hashmap and store the student data , key is roll no 1,2,3, etc and value is name of student a,b,c and access  the name of roll -no = 2 .




import java.util.HashMap;

public class basichashmap {
    public static void main(String[ ] args) {
        HashMap<Integer, String> student = new HashMap<Integer,String >();
        student.put(1, "a");
        student.put(2, "b");
        student.put(3, "c");
        System.out.println(student.get(2));
    }
}



OUTPUT: 
b



No comments:

Post a Comment

GitHub Most Imp Command For Every Developer Learn:

 Top Command for GitHub:  1) git clone 2) git init and git status   3) git add file name  or git add .  4) git commit -m message  5) git rem...