Explore what CodeHS has to offer for districts, schools, and teachers.
Click on one of our programs below to get started coding in the sandbox!
View All
What value will be printed in the console after this series of commands? Assume that the ArrayList package has been imported.
ArrayList<String> colors = new ArrayList<String>(); colors.add("red"); colors.add("blue"); colors.add("orange"); colors.add("green"); String firstColor = colors.remove(0); String secondColor = colors.set(1, "yellow"); colors.add(3, firstColor); System.out.println("Colors: " + secondColor + " and " + colors.get(1));
Colors: orange and yellow
Colors: yellow and blue
Colors: orange and blue
Colors: yellow and yellow
This will cause an error, as colors.remove cannot be assigned to a value.
colors.remove