Remove Null Value from String array in java

前端 未结 8 647
囚心锁ツ
囚心锁ツ 2020-11-29 08:16

How to remove null value from String array in java?

String[] firstArray = {\"test1\",\"\",\"test2\",\"test4\",\"\"};

I need the \"firstArra

8条回答
  •  既然无缘
    2020-11-29 08:53

    Those are zero-length strings, not null. But if you want to remove them:

    firstArray[0] refers to the first element
    firstArray[1] refers to the second element
    

    You can move the second into the first thusly:

    firstArray[0]  = firstArray[1]
    

    If you were to do this for elements [1,2], then [2,3], etc. you would eventually shift the entire contents of the array to the left, eliminating element 0. Can you see how that would apply?

提交回复
热议问题