Removing duplicate strings from an array?

前端 未结 9 821
野的像风
野的像风 2021-01-24 06:54

How can I remove duplicate strings from a string array without using a HashSet?

I try to use loops, but the words not delete.

StringBuffer outString = ne         


        
9条回答
  •  温柔的废话
    2021-01-24 07:21

    In your inner loop, initialize j = i + 1

    if(wordlist[i] != null && wordlist[i].equals(worldlist[j])) { wordlist[j] = null; }
    

    ...and then compact the array when you're finished to remove all null values

提交回复
热议问题