Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class ArrListExample {
- public static void main(String[] args) {
- Scanner userInput = new Scanner(System.in);
- ArrayList<String> cityPop = new ArrayList<String>();
- cityPop.add("Tokyo, Japan - 28,025,000");//ADD METHOD
- cityPop.add("Philadelpia, USA - 8,131,000");
- cityPop.add("Mexico City, Mexico - 8,131,000");
- cityPop.add("Mumbai, India - 1,042,000");
- cityPop.add("New York City, USA - 16,626,000");
- cityPop.remove(1);//removes that elements and shifts rest down
- cityPop.add(3,"Sáo Paulo, Brazil - 7, 711,000");
- //ANOTHER ADD METHOD - places in 3rd slot and slides rest down
- /*
- * NOTE: if you run this program as is, nothing will show to the screen
- * Use the for loop below to print the cityPop array to the screen
- See if the order is what you expected.
- Also, use the remove and set methods to add and remove
- elements from the ArrayList. See if it works as intended.
- */
- for (int i=0; i<cityPop.size();i++){//SIZE METHOD
- // FILL IN BODY
- }
- }
- }
Add Comment
Please, Sign In to add comment