Delete duplicate strings in string array

后端 未结 13 2104
执念已碎
执念已碎 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 00:45

    Set data structure will do automatically the job for. Most likely option for you will be HashSet, if you care about the order of elements look at TreeSet

    List input = Arrays.asList(array);
    Set unique = new HashSet<>(input);
    

提交回复
热议问题