I need to convert a HashMap to an array; could anyone show me how it\'s done?
If you are using Java 8+ and need a 2 dimensional Array, perhaps for TestNG data providers, you can try:
map.entrySet()
.stream()
.map(e -> new Object[]{e.getKey(), e.getValue()})
.toArray(Object[][]::new);
If your Objects are Strings and you need a String[][], try:
map.entrySet()
.stream()
.map(e -> new String[]{e.getKey(), e.getValue().toString()})
.toArray(String[][]::new);