How do I take a String[]
, and make a copy of that String[]
, but without the first String?
Example: If i have this...
String[] color
Forget about arrays. They aren't a concept for beginners. Your time is better invested learning the Collections API instead.
/* Populate your collection. */
Set colors = new LinkedHashSet<>();
colors.add("Red");
colors.add("Orange");
colors.add("Yellow");
...
/* Later, create a copy and modify it. */
Set noRed = new TreeSet<>(colors);
noRed.remove("Red");
/* Alternatively, remove the first element that was inserted. */
List shorter = new ArrayList<>(colors);
shorter.remove(0);
For inter-operating with array-based legacy APIs, there is a handy method in Collections
:
List colors = new ArrayList<>();
String[] tmp = colorList.split(", ");
Collections.addAll(colors, tmp);