Removing empty element from Array(Java)

后端 未结 5 809
遇见更好的自我
遇见更好的自我 2020-12-10 09:12

I\'m trying to remove the empty element from the array by copying the existing element to a new array. However, initialization of the new array is causing my return value to

5条回答
  •  情书的邮戳
    2020-12-10 09:49

    There are few things Which I am putting as points below. Hope you will get help from this.

    1. String store[] = new String[words.length] instantiates an array of Strings but It does not instantiate any of the elements with any non null value. Default value is null so this is an array of null Strings.
    2. (words[i] != target) should be replaced with

      (!words[i].equals(target))

提交回复
热议问题