For example we have
String [][] doubleArray = {{"a","1"},{"b","3"},{"a","1"},{"c","1"}};
.
How can i create a new array with only uniqueness subarrays :
{{"a","1"},{"b","3"},{"c","1"}}
What i tryed :
Set <String []> uniq = new HashSet<String []>(Arrays.asList(doubleArray));
But Java doesnt see the difference between {"a","1"}
and {"a","1"}
, so uniq
returns me set of all subarrays of doubleArray
, including clones.
You can use Map
like this:
String [][] doubleArray = {{"a","1"},{"b","3"},{"a","1"},{"c","1"}};
Map<String, String> map = new HashMap<>();
for (String[] strings : doubleArray) {
map.put(strings[0], strings[1]);
}
System.out.println("map = " + map);
The result:
map = {a=1, b=3, c=1}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments