1 2 3 4 5 6 7 | 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(); } |


1 2 3 4 5 6 7 | 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(); } |
1 2 3 4 5 6 7 8 9 10 11 | 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(); } } |
1 2 3 4 5 6 7 8 9 10 11 12 | 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(); } } |
1 2 | List<Boat> ships = getObjects(Boat. class ); (ships.get(x)).aMethod(); |