Download
arraylist review solutions n.
Skip this Video
Loading SlideShow in 5 Seconds..
ArrayList Review Solutions PowerPoint Presentation
Download Presentation
ArrayList Review Solutions

ArrayList Review Solutions

79 Vues Download Presentation
Télécharger la présentation

ArrayList Review Solutions

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. ArrayList Review Solutions How would you create an array list to store the cities in North Carolina?ArrayList<String> cities = new ArrayList<String>(); How would you put “Greensboro” and “Raleigh” into this array list?cities.add(“Greensboro”); cities.add(“Raleigh”); Suppose the array list is full of cities, but the last city inserted is a duplicate and needs to be removed. How would you remove the last city?cities.remove(cities.size()-1);

  2. ArrayList Review Solutions “Kernersville” changed its name to “K-Vegas”. Find this element and change it.for (int i=0; i<cities.size(); i++){ if (cities.get(i).equals(“Kernersville”) { cities.set( i,”K-Vegas”); break; }} You need to start over and get rid of all the cities in the array list. How would you do that?cities.clear();

  3. import java.util.ArrayList;