Guest User

Untitled

a guest
Oct 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class ArrListExample {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner userInput = new Scanner(System.in);
  8.  
  9. ArrayList<String> cityPop = new ArrayList<String>();
  10.  
  11. cityPop.add("Tokyo, Japan - 28,025,000");//ADD METHOD
  12. cityPop.add("Philadelpia, USA - 8,131,000");
  13. cityPop.add("Mexico City, Mexico - 8,131,000");
  14. cityPop.add("Mumbai, India - 1,042,000");
  15. cityPop.add("New York City, USA - 16,626,000");
  16.  
  17. cityPop.remove(1);//removes that elements and shifts rest down
  18.  
  19. cityPop.add(3,"Sáo Paulo, Brazil - 7, 711,000");
  20. //ANOTHER ADD METHOD - places in 3rd slot and slides rest down
  21.  
  22.  
  23. /*
  24. * NOTE: if you run this program as is, nothing will show to the screen
  25.  
  26. * Use the for loop below to print the cityPop array to the screen
  27.  
  28. See if the order is what you expected.
  29.  
  30. Also, use the remove and set methods to add and remove 
  31.  
  32. elements from the ArrayList. See if it works as intended.
  33. */
  34.  
  35. for (int i=0; i<cityPop.size();i++){//SIZE METHOD 
  36.  
  37. // FILL IN BODY
  38.  
  39. }
  40.  
  41. }
  42. }
Add Comment
Please, Sign In to add comment