How can add element in Array / ArrayList an dloop through it key and value

PHOTO EMBED

Sat Apr 13 2024 10:42:39 GMT+0000 (Coordinated Universal Time)

Saved by @Divya ##array #hashmap

int[] arr = {1,2,3,4,5,6};
          for(int i =0; i<arr.length; i++){
            System.out.println("key "  + arr[i]);
        }
        
        ----------------
        ArrayList<Integer> arr = new ArrayList<>();
        arr.add(1);
        arr.add(3);
         arr.add(5);
          arr.add(6);
        
        for(int i =0; i<arr.size(); i++){
            System.out.println("key "  + arr.get(i));
        }


--------------
Map<String, Integer> map = new HashMap<String, Integer>();
      
      map.put("key", 11);
      map.put("key1", 11);
      map.put("key2", 11);
      map.put("key3", 15);
      map.put("key4", 11);
      map.put("key5", 11);
      map.put("key6", 11);
      
      for(Map.Entry<String, Integer> entry : map.entrySet()){
          String key = entry.getKey();
          int value = entry.getValue();
          
          System.out.println(" "+ key + " "+ value);
      }

---------------------------
  
content_copyCOPY

Gigame Portal