I have a List of Strings as ["abc", "xyz", "abc", "mno", "123"]
now I want the unique values out of this list. To do that I am converting the List to HashSet.
I am able to achieve the same but the order of elements is affected. The output is very random, one of the result is ["123", "xyz", "abc", "mno"]
.
But I want resulted set containing the items in the same order as the arraylist. How can I achieve this?
List<String> parameters = new ArrayList<String>();
//add the parameter to List
Set<String> parameterSet=new HashSet<String>(parameters);
Use LinkedHashSet
List<String> parameters = new ArrayList<String>();
Call the List here
|
Set<String> parameterSet=new LinkedHashSet<String>(parameters);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With