有一点它比较array(1)compareto(array(1))这是一个问题吗?鸟类数量是数组中元素的数量。我正在尝试删除数组中的重复字符串。它是可修复的还是我应该重新处理?

for (i = 0; i <= amountBirds - 1; i++)
{
    for (x = 1; x <= amountBirds; x++)
    {
        duplicate = birdArray[i].compareTo(birdArray[x]);

        if (duplicate == 0)
        {
            birdArray[i] = birdArray[x];
        }
    }
}

最佳答案

尝试这个:

birdArray = new HashSet<String>(Arrays.asList(birdArray)).toArray(new String[0]);

09-11 18:07