Doesn't iterate in expected order. My first thought was some version of LinkedList (as below). This would give the expected output if lines 22, 23 were exchanged. After that, I think I've looked at all the implementations of map. . .
Thanks for any help!!!
package com.codegym.task.task37.task3704;
import java.util.*;
import java.util.concurrent.ConcurrentSkipListMap;
/*
Bug fix
*/
public class Solution {
public static void main(String[] args) {
Map expectedMap = getExpectedMap();
System.out.println("********* Add obj with key NULL *********");
expectedMap.put(null, "text 1");
System.out.println(expectedMap.size());
System.out.println(expectedMap.get(null));
System.out.println("********* Add obj with key 0 *********");
expectedMap.put(0, "text 2");
System.out.println(expectedMap.size());
System.out.println(expectedMap.get(null));
System.out.println(expectedMap.get(0));
System.out.println("********* Keys *********");
for (Object o : expectedMap.keySet()) {
System.out.println(o);
}
System.out.println("********* Values *********");
for (Object o : expectedMap.values()) {
System.out.println(o);
}
/* Expected output
********* Add obj with key NULL *********
1
text 1
********* Add obj with key 0 *********
2
text 1
text 2
********* Keys *********
0
null
********* Values *********
text 2
text 1
*/
}
public static Map getExpectedMap() {
return new LinkedHashMap(16, 0.75f, true);
}
}