top of page

Edabit Java: Numbers in Strings; Medium Difficulty


  • I solved this question using a ArrayList

  • Not sure if it was the best solution but it worked!




import java.util.ArrayList;

public class Challenge {

public static String[] numInStr(String[] arr) {

ArrayList words = new ArrayList();

for(String i : arr) {

if(i.matches(".*\\d.*"))

words.add(i);

}

String[] j = new String[words.toArray().length];

for(int i = 0; i < j.length; i++) {

j[i] = (String) words.get(i);

}

return j;

}

}


5 views0 comments
Post: Blog2_Post
bottom of page