Run ❯
Get your
own Java
server
×
Change Orientation
Change Theme, Dark/Light
Go to Spaces
import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList
cars = new ArrayList
(); cars.add("Volvo"); cars.add("BMW"); cars.add("Ford"); cars.add("Mazda"); ArrayList cars2 = (ArrayList)cars.clone(); cars2.set(0, "Toyota"); System.out.println(cars); System.out.println(cars2); } }
[Volvo, BMW, Ford, Mazda]
[Toyota, BMW, Ford, Mazda]