java - 如何仅使用数组和循环(没有其他方法)来删除 null?

标签 java arrays

我这里有这段代码,输出带有null。我怎样才能删除它?

输入是:

hello hello i i am norman

      for (int i=0; i<words.length; i++){
        boolean isUnique = true;
        int freq = 0;
        for (int j=0; j<words.length; j++){
            if (i==j){
                freq++;
                 continue;
            }
            if (words[j].equals(words[i])){
                 isUnique = false;
                freq++;
            }
        }

        if (isUnique){

            uniquewords[i] = words[i];}

        frequency[i] = freq;

       }

    }

输出:

null null null null am norman

最佳答案

if (uniquewords[i] != null){
   System.out.println(uniquewords[i]);
}

打印时添加此检查

关于java - 如何仅使用数组和循环(没有其他方法)来删除 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59195275/

相关文章:

javascript - 比较数组中的数组

java - 通过 SOCKS Proxy 连接到 Kafka

java - Commons-Net FTPClient 无法正确下载文件

java - 静态方法的使用

java - 如何 Autowiring Spring Environment 对象

arrays - 如何在 React + Typescript 中检查数组中 javascript 对象的所有值是否为真?

c++ - 寻找 2 个 vector 的交集算法评论/解释

java - 如何使用 Spring MVC 获取用户 ID?

javascript - 如何 "undo"带有拼接的已删除元素?

python - 从椭圆生成数组