At first Sorry if title doesn't really explain the problem as it should be.
I have 2 ArrayList in my android (java) code
as example lets say the first is made of strings and the second is made of integers.
ArrayLis<String> strings = new ArrayList<String>();
strings.add("s1");
strings.add("s2");
strings.add("s1");
strings.add("s3");
strings.add("s4");
strings.add("s1");
strings.add("s2");
ArrayList<Integer> ints = new ArrayList<Integer>();
ints.add(1);
ints.add(2);
ints.add(5);
ints.add(3);
ints.add(4);
ints.add(3);
ints.add(2);
Taking this example, lets say each value in array list strings correspond to a value of array ints but the int value might change
I want to remove the repetition in the string array, I used LinkedHashSet to do so:
LinkedHashSet<String>hashset = new LinkedHashSet<>(strings);
strings = new ArrayList<> hashset;
The issue now is i removed the duplicate string entries but i also removed the link between each string and its int value.
how can I get the new "ints" array using the minimal int value for the string for example for s1 that has 1, 5 and 3 as bound values get the 1 value as so:
strings = ["s1", "s2", "s3", "s4"];
ints = [1, 2, ,3, 4];
I thought of using maps. but is it the best way to do it? (map the string to the int and whenever a repetition occures check int if smaller and replace map value)