Java Basic - HashMap

Java Basic - Konsep HashMap di Java

class Basic_HashMap {
    public static void main(String[]args){
        
        ArrayList<HashMap> data = new ArrayList<>();
        HashMap<String, String> hash;
        hash = new HashMap<>();
        hash.put("nim", "10510269");
        hash.put("nama", "Ardiansyah");
        hash.put("jurusan", "Sistem Informasi");

        data.add(hash);
        System.out.println("Nim : " + data.get(0).get("nim"));
        System.out.println("Nama : " + data.get(0).get("nama"));
        System.out.println("Jurusan : " + data.get(0).get("jurusan"));

        System.out.println("data ke[0] : " + data.get(0));

        hash.put("nim", "10510260");
        hash.put("nama", "Wiro Sableng");
        hash.put("jurusan", "Teknik Bela Diri");

        data.add(hash);
        System.out.println("data ke[1] : " + data.get(1));    
        
    /*
    Nim : 10510269
    Nama : Ardiansyah
    Jurusan : Sistem Informasi
    
    data ke[0] : {jurusan=sistem informasi, nama=Ardiansyah, nim=10510269}
    data ke[1] : {jurusan=Teknik Bela Diri, nama=Wiro Sableng, nim=10510260}
    */
    
    }
}


About Author

Ardie Jocong

let's we learn coding together ,.. Learning by doing.. cause the best way of learning about anything is by doing. explore your brain ..


Comment & Discussions

    Please LOGIN before if you want to give the comment.