See*_*ker 3 java arraylist set
我有一个字符串列表 ["abc", "xyz", "abc", "mno", "123"]
现在我想要这个列表中的唯一值.为此,我将List转换为HashSet.
我能够实现相同但元素的顺序受到影响.输出是非常随机的,其中一个结果是["123", "xyz", "abc", "mno"].
但我希望结果集包含与arraylist相同顺序的项目.我怎样才能做到这一点?
List<String> parameters = new ArrayList<String>();
//add the parameter to List
Set<String> parameterSet=new HashSet<String>(parameters);
Run Code Online (Sandbox Code Playgroud)
使用 LinkedHashSet
List<String> parameters = new ArrayList<String>();
Call the List here
|
Set<String> parameterSet=new LinkedHashSet<String>(parameters);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2929 次 |
| 最近记录: |