Delete duplicate strings in string array

后端 未结 13 2093
执念已碎
执念已碎 2020-12-30 00:33

I am making a program based on string processing in Java in which I need to remove duplicate strings from a string array. In this program, the size of all strings are same.

13条回答
  •  佛祖请我去吃肉
    2020-12-30 01:02

    Sring[] myStringArray = {"hello", "hello", "moto"};
    String[] filteredArray = new LinkedHashSet(Arrays.asList(myStringArray))
                             .toArray(new String[0]);
    
    System.out.println("filteredArray Size: " + filteredArray.length);
    System.out.println("filteredArray[0] = " + filteredArray[0]);
    System.out.println("filteredArray[1] = " + filteredArray[1]);
    

提交回复
热议问题