Forget about arrays. They are not concepts for beginners. Itβs best to invest your time in learning about the API collections.
Set<String> colors = new LinkedHashSet<>(); colors.add("Red"); colors.add("Orange"); colors.add("Yellow"); ... Set<String> noRed = new TreeSet<>(colors); noRed.remove("Red"); List<String> shorter = new ArrayList<>(colors); shorter.remove(0);
Collections
have a convenient method for interacting with legacy array-based APIs:
List<String> colors = new ArrayList<>(); String[] tmp = colorList.split(", "); Collections.addAll(colors, tmp);
source share