Opérations sur les tableaux
Assignation de tableau, références
import java.util.Vector; class Auto{ int max_speed; String brand; Auto(int s, String brand){ max_speed = s; this.brand = brand; } public String toString() { return brand + " - " + max_speed; } } public class VectorLive { public static void main(String[] args) { Auto a1 = new Auto(120, "Golf GTI"); Auto a2 = new Auto(100, "Smart 4x4"); // Create a vector for autos Vector<Auto> autos = new Vector<Auto>(); autos.add(a1); autos.add(a2); autos.add(new Auto(130, "Audi TT")); if(autos.isEmpty()) { System.out.println("No autos in the collection"); } else System.out.println("There are " + autos.size() + " autos in the collection"); if(autos.contains(a2)) System.out.println("The car a2 is in the collection"); else System.out.println("The car a2 is not in the collection"); for(Auto a : autos) { System.out.println(a); } } }