0% found this document useful (0 votes)
13 views2 pages

Java HashMap Example and Operations

The document demonstrates how to use a HashMap in Java by creating a HashMap that maps integer keys to food item strings. It adds several key-value pairs, prints the HashMap and size, checks if a key exists, removes a key-value pair, and clears the entire HashMap, outputting the results at each step.

Uploaded by

Rudi Saputra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Java HashMap Example and Operations

The document demonstrates how to use a HashMap in Java by creating a HashMap that maps integer keys to food item strings. It adds several key-value pairs, prints the HashMap and size, checks if a key exists, removes a key-value pair, and clears the entire HashMap, outputting the results at each step.

Uploaded by

Rudi Saputra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Contoh program Hashmap :

import [Link];

public class Main {

public static void main(String[] args) {

HashMap<Integer, String> cul = new HashMap<Integer, String>();

//menambahkan data ke hashmap

[Link](101, "Gado-Gado");

[Link](102, "Sate Iwak");

[Link](103, "Ragit");

[Link](104, "Daging balado");

//menampilkan hashmap

[Link]("Hashmap \t\t\t : " + [Link]());

[Link]("Ukuran Hashmap \t\t\t : " + [Link]());

//mengecek data di hashmap

[Link]("Ada Sate Iwak? \t\t\t : " + [Link](102));

//men-delete data di hashmap

[Link]("Removed \t\t\t : " + [Link](104));

[Link]("Hashmap \t\t\t : " + [Link]());

[Link]("Ukuran Hashmap \t\t\t : " + [Link]());

//menghapus semua data

[Link]();
[Link]("Seluruh items HashMap dihapus \t : " + cul);

}//main

Output program :

You might also like