[Solved] how to get specific value from string array and save it to another string array?


Since you’re working with arrays and not ArrayList objects, things get a little tedious. The following code runs through the first array, checks if the current String is not the one you don’t want, and increases the counter by one if it has found one you do want. It then creates a new array as big as the number of objects you want in the initial array, runs through the intial array again, this time adding the String obejcts you want to the second array.

String[] arrayOne = {"65535", "00000", "00000", "00000", "00000",
        "A32CE", "43251", "98702", "ACED2", "98AAB",
        "00000", "00000", "00000", "65535", "65535"};

int validCounter = 0;
for(int i = 0; i < arrayOne.length; i++)
  if(!(arrayOne[i].equals("65535") || arrayOne[i].equals("00000")))
      validCounter++;

String[] arrayTwo = new String[validCounter];
int arrayTwoPos = 0;
for(int i = 0; i < arrayOne.length; i++)
  if(!(arrayOne[i].equals("65535") || arrayOne[i].equals("00000"))){
      arrayTwo[arrayTwoPos] = arrayOne[i];
      arrayTwoPos++;
  }

for(int i = 0; i < arrayTwo.length; i++)
    System.out.println(arrayTwo[i]);

1

solved how to get specific value from string array and save it to another string array?