void () { String filtersText = myInstanceFiltersField.getText(); ArrayList<InstanceFilter> idxs = new ArrayList<>(); int startNumber = -1; for (int i = 0; i <= filtersText.length(); i++) { if (i < filtersText.length() && Character.isDigit(filtersText.charAt(i))) { if (startNumber == -1) { startNumber = i; } } else { if (startNumber >= 0) { idxs.add(InstanceFilter.create(filtersText.substring(startNumber, i))); startNumber = -1; } } } for (InstanceFilter instanceFilter : myInstanceFilters) { if (!instanceFilter.isEnabled()) { idxs.add(instanceFilter); } } myInstanceFilters = idxs.toArray(InstanceFilter.EMPTY_ARRAY); }