جاوا ۾ entrySet() طريقو ڇا آهي؟
HashMap ڪلاس مهيا ڪري ٿو java.util.HashMap.entrySet () طريقو جاوا ۾. اهو ٺاهڻ لاءِ استعمال ڪيو ويندو آهي ۽ پوءِ ساڳيو عنصرن جو هڪ 'سيٽ' واپس ڪرڻ لاءِ جيڪي اڳ ۾ ئي موجود آهن HashMap . اهو هڪ لوپ سان استعمال ڪري سگهجي ٿو 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=نال، 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