ஜாவாவில் என்ட்ரிசெட்() முறை என்ன?
HashMap வகுப்பு ஜாவாவில் java.util.HashMap.entrySet() முறையை வழங்குகிறது . HashMap இல் ஏற்கனவே இருக்கும் அதே கூறுகளின் 'தொகுப்பை' உருவாக்கவும், பின்னர் திரும்பப் பெறவும் இது பயன்படுகிறது . ஹாஷ்மேப்பின் அனைத்து உள்ளீடுகளையும் மீண்டும் செய்ய இது ஒரு வளையத்துடன் பயன்படுத்தப்படலாம் .முறை தலைப்பு
entrySet() முறையின் தலைப்பு கீழே கொடுக்கப்பட்டுள்ளது. விசை-மதிப்பு ஜோடிகளைக் கொண்ட அனைத்து உள்ளீடுகளின் தொகுப்பு பார்வையை இது வழங்குகிறது. அதை எங்கள் குறியீட்டில் பயன்படுத்த java.util.HashMap தொகுப்பை இறக்குமதி செய்ய வேண்டும் .public Set<Map.Entry<key, value>> entrySet()
அளவுருக்கள்
entrySet () முறை எந்த அளவுருக்களையும் எடுக்காது.திரும்பும் வகை
java.util.HashMap.entrySet () முறையானது கிளாஸ் செட்டின் ஒரு நிகழ்வை வழங்குகிறது.உதாரணமாக
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');
}
}
வெளியீடு
அசல் HashMap: {1=திங்கள், 2=செவ்வாய், 3=புதன், 4=வியாழன், 5=வெள்ளி, 6=சனி, 7=ஞாயிறு} HashMap.entrySet(): [1=திங்கட்கிழமை, 2=செவ்வாய், 3=புதன்கிழமை , 4=வியாழன், 5=வெள்ளிக்கிழமை, 6=சனிக்கிழமை, 7=ஞாயிறு] hashMap.put(0, null) HashMap.entrySet(): [0=null, 1=திங்கட்கிழமை, 2=செவ்வாய், 3=புதன், 4= வியாழன், 5=வெள்ளிக்கிழமை, 6=சனிக்கிழமை, 7=ஞாயிறு] hashMap.put(null, null) HashMap.entrySet(): [0=null, null=null, 1=திங்கட்கிழமை, 2=செவ்வாய், 3=புதன், 4 =வியாழன், 5=வெள்ளிக்கிழமை, 6=சனிக்கிழமை, 7=ஞாயிறு] hashMap.put(null, "\0") HashMap.entrySet(): [0=null, null= , 1=திங்கட்கிழமை, 2=செவ்வாய், 3= புதன், 4=வியாழன், 5=வெள்ளிக்கிழமை, 6=சனி, 7=ஞாயிறு]
GO TO FULL VERSION