జావాలో ఎంట్రీసెట్() పద్ధతి అంటే ఏమిటి?
HashMap తరగతి జావాలో java.util.HashMap.entrySet ( ) పద్ధతిని అందిస్తుంది . HashMap లో ఇప్పటికే ఉన్న అదే మూలకాల యొక్క 'సెట్'ని సృష్టించి, ఆపై తిరిగి ఇవ్వడానికి ఇది ఉపయోగించబడుతుంది . ఇది HashMap యొక్క అన్ని ఎంట్రీలను మళ్ళించడానికి లూప్తో ఉపయోగించవచ్చు .పద్ధతి శీర్షిక
ఎంట్రీసెట్() పద్ధతి యొక్క హెడర్ క్రింద ఇవ్వబడింది. ఇది కీ-విలువ జతలను కలిగి ఉన్న అన్ని ఎంట్రీల సెట్ వీక్షణను అందిస్తుంది. దీన్ని మా కోడ్లో ఉపయోగించడానికి మనం 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=శూన్యం, 1=సోమవారం, 2=మంగళవారం, 3=బుధవారం, 4= గురువారం, 5=శుక్రవారం, 6=శనివారం, 7=ఆదివారం] hashMap.put(శూన్య, శూన్య) HashMap.entrySet(): [0=శూన్య, శూన్య=శూన్య, 1=సోమవారం, 2=మంగళవారం, 3=బుధవారం, 4 =గురువారం, 5=శుక్రవారం, 6=శనివారం, 7=ఆదివారం] hashMap.put(null, "\0") HashMap.entrySet(): [0=null, null= , 1=సోమవారం, 2=మంగళవారం, 3= బుధవారం, 4=గురువారం, 5=శుక్రవారం, 6=శనివారం, 7=ఆదివారం]