Help determining data type

This is my Java attempt on that positive number filter challenge: :coffee:

“Program.java”:

import java.util.Collection;
import java.util.LinkedHashSet;

public final class Program {
  @SafeVarargs static public final String[] filterArray(final String... strs) {
    if (strs == null || strs.length == 0)  return new String[0];

    final Collection<String> nums = new LinkedHashSet<>();

    for (final String str : strs)  try {
      Integer.parseUnsignedInt(str);
      nums.add(str);
    }

    catch (final NumberFormatException notPositiveNumber) {
    }

    return nums.toArray(new String[nums.size()]);
  }
}

But b/c I haven’t created an account on Edabit.com yet I couldn’t check my code there. :woozy_face:

However I’ve come up with this PDE sketch to test my “Program.java” file on Processing: :flushed:

void setup() {
  println(Program.filterArray("1", "2", "a", "b"));
  println(Program.filterArray("1", "a", "b", "0", "15"));
  println(Program.filterArray("1", "2", "aasf", "1", "123", "123"));
  println(Program.filterArray("jsyt", "4", "yt", "6"));
  println(Program.filterArray("r", "5", "y", "e", "8", "9"));
  println(Program.filterArray("a", "e", "i", "o", "u"));
  println(Program.filterArray("4", "z", "f", "5"));
  println(Program.filterArray("abc", "123"));
  println(Program.filterArray("$%^", "567", "&&&"));
  println(Program.filterArray("w", "r", "u", "43", "s", "a", "76", "d", "88"));
  exit();
}
1 2
1 0 15
1 2 123
4 6
5 8 9

4 5
123
567
43 76 88
1 Like