Assume there is only one null in an array. I am trying to move it right to the end using a for loop. this is what i tried.
String example[] = new String[5];
example[0] = "a";
example[1] = null;
example[2] = "c";
example[3] = "d";
example[4] = "e";
I want the output to be : a,c,d,e,null. I want to able to move the null to the end regardless of its index using a FOR loop.
This is what i tried
String asd[] = new String[creatureList.length];
for (int i = 0 ; i < creatureList.length; i++) {
if (creatureList[i] != null){
asd[i] = creatureList[i];
}
creatureList = asd;