Apa metode entrySet () ing Jawa?
Kelas HashMap nyedhiyakake metode java.util.HashMap.entrySet () ing Jawa. Iki digunakake kanggo nggawe banjur ngasilake 'set' saka unsur sing padha sing wis ana ing HashMap . Bisa digunakake kanthi daur ulang kanggo ngulang kabeh entri HashMap .Metode Header
Header metode entrySet () diwenehi ing ngisor iki. Iki ngasilake tampilan set kabeh entri sing ngemot pasangan kunci-nilai. Kanggo nggunakake ing kode kita kudu ngimpor paket java.util.HashMap .public Set<Map.Entry<key, value>> entrySet()
Paramèter
Cara entrySet () ora njupuk paramèter.Jinis bali
Cara java.util.HashMap.entrySet () ngasilake conto saka set kelas.Tuladha
import java.util.HashMap;
public class Driver1 {
public static void main(String[] args) {
// declare a custom hash map
HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
// add data to the hash map
hashMap.put(1, "Monday");
hashMap.put(2, "Tuesday");
hashMap.put(3, "Wednesday");
hashMap.put(4, "Thursday");
hashMap.put(5, "Friday");
hashMap.put(6, "Saturday");
hashMap.put(7, "Sunday");
// print the original hash map
System.out.println("Original HashMap: " + hashMap + '\n');
// print the entrySet of the hash map
System.out.println("HashMap.entrySet(): " + hashMap.entrySet() + '\n');
// Try adding null value in the hash map
hashMap.put(0, null);
System.out.println("hashMap.put(0, null)");
System.out.println("HashMap.entrySet(): " + hashMap.entrySet() + '\n');
// Try adding null key and value pair to the hash map
hashMap.put(null, null);
System.out.println("hashMap.put(null, null)");
System.out.println("HashMap.entrySet(): " + hashMap.entrySet() + '\n');
// Try adding a null character as a value in the hash map
hashMap.put(null, "\0");
System.out.println("hashMap.put(null, \"\\0\")");
System.out.println("HashMap.entrySet(): " + hashMap.entrySet() + '\n');
}
}
Output
HashMap Asli: {1=Senin, 2=Selasa, 3=Rebo, 4=Kemis, 5=Jumuah, 6=Sabtu, 7=Minggu} HashMap.entrySet(): [1=Senin, 2=Selasa, 3=Rebo , 4 = Kamis, 5 = Jum'at, 6 = Setu, 7 = Minggu] hashMap.put (0, null) HashMap.entrySet (): [0 = null, 1 = Senin, 2 = Selasa, 3 = Rebo, 4 = Kamis, 5 = Jum'at, 6 = Setu, 7 = Minggu] hashMap.put(null, null) HashMap.entrySet(): [0=null, null=null, 1=Senin, 2=Selasa, 3=Rebo, 4 = Kamis, 5 = Jumuah, 6 = Setu, 7 = Minggu] hashMap.put(null, "\0") HashMap.entrySet(): [0=null, null=, 1=Senin, 2=Selasa, 3= Rebo, 4 = Kemis, 5 = Jumuah, 6 = Setu, 7 = Minggu]