“Peta Interation di Java” Kode Jawaban

Peta Interation di Java

Map map = new HashMap();
Iterator entries = map.entrySet().iterator();
while (entries.hasNext()) {
    Map.Entry entry = (Map.Entry) entries.next();
    Integer key = (Integer)entry.getKey();
    Integer value = (Integer)entry.getValue();
    System.out.println("Key = " + key + ", Value = " + value);
}
Careful Cockroach

Peta Interation di Java

Map<Integer, Integer> map = new HashMap<Integer, Integer>();

// Iterating over keys only
for (Integer key : map.keySet()) {
    System.out.println("Key = " + key);
}

// Iterating over values only
for (Integer value : map.values()) {
    System.out.println("Value = " + value);
}
Careful Cockroach

Peta Interation di Java

Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
Careful Cockroach

Jawaban yang mirip dengan “Peta Interation di Java”

Pertanyaan yang mirip dengan “Peta Interation di Java”

Lebih banyak jawaban terkait untuk “Peta Interation di Java” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya