List ships = getObjects(Boat.class); int[] shipsOnSea = new int [10]; // The tens are the length of the List ships for (int i = 0; i < 10; i++) { shipsOnSea[i] = (ships.get(i)).getX(); }
List ships = getObjects(Boat.class); int[] shipsOnSea = new int [10]; // The tens are the length of the List ships for (int i = 0; i < 10; i++) { shipsOnSea[i] = (ships.get(i)).getX(); }
List ships = getObjects(Boat.class); int leftX = 999; // to track lowest X coordinate Boat leftBoat = null; // to hold the leftmost boat found so far for (Boat ship : ships) // format of 'for' to iterate through a list { if (ship.getX() < leftX) { leftBoat = ship; leftX = ship.getX(); } }
List ships = getObjects(Boat.class); int leftX = 999; // to track lowest X coordinate Boat leftBoat = null; // to hold the leftmost boat found so far for (int i = 0; i < ships.size(); i++) // format of 'for' to iterate through a list { if ((ships.get(i)).getX() < leftX) { leftBoat = ships; leftX = ships.get(i).getX(); } }
List<Boat> ships = getObjects(Boat.class); (ships.get(x)).aMethod();