**I have a hashmap in java in which I store for test:**

```
HashMap<String, String> hmap = new HashMap<Integer, String>();

 //add elements to HashMap
 hmap.put("1", "AA");
 hmap.put("2", "BB");
 hmap.put("3", "CC");
 hmap.put("4", "DD");

```

**Then I want to group my key-values by pairs**

```
 for(String id1: hmap.keySet()) {
            Integer id2 = Integer.valueOf(id1)+1;
            while(id2 <= 4){
                String IDs = id1 + "/" + String.valueOf(id2);
                String Contents = hmap.get(id1) + "/" + hmap.get(String.valueOf(id2));
                System.out.println(IDs);
                System.out.println(Contents);
                id2++;
            }
        }

```

**But I obtain as a result:**

```
1/2
AA/null
1/3
AA/null
1/4
AA/null
2/3
BB/null
2/4
BB/null
3/4
CC/null

```

While I was hoping

```
1/2
AA/BB
1/3
AA/CC
...

```

The code I post is just for example. I have a HashMap with (ID, value) and I want to create a new HashMap with all pairs of ID (one time each) and pairs of value. But the hmap.get(String.valueOf(id2)) returns always a "null" value.

Can someone explain why the second value is null and what I can do to remediate?