Given an array. How do I find all of the words in the list that are greater than three characters and add them to a new list
public class RunnerClass {
public static int counter;
public static int index=0;
public static void main(String[]args){
/*String mainArr[]= new String[5];
mainArr[0]="Taco";
mainArr[1]="Pizza";
mainArr[2]="Hi";
mainArr[3]="tryy";
mainArr[4]="live";*/
String[]myWords = {"Hi", "taco", "g"};
System.out.println(removeStopWord(myWords));
System.out.println(counter);
}
public static String[] removeStopWord(String [] arr){
counter=0;
//String [] methodArr = new String[counter];
//int index=0;
for(String keep : arr){
if(3<keep.length()){
counter++;
}
}
String [] methodArr = new String[counter];
index=0;
for (int i = 0; i < arr.length ; i++){
if (arr[i].length() > 3){
methodArr[index]=arr[i];
index++;
}
}
return methodArr;
}
}