Title: ArrayList
1ArrayList
2Arrays as Classes - ArrayList
import java.util. public class Students
public static void main(String args)
String tempName ArrayList students new
ArrayList() tempNameGetData.getString("Ente
r last name") while(tempName.length()gt0)
students.add(tempName)
tempNameGetData.getString("Enter last name")
if (! students.isEmpty())
Collections.sort(students)
System.out.println("\n\nSTUDENTS")
Iterator x students.iterator() while
(x.hasNext()) System.out.println((String)
x.next())
3Homework 3 part 5
- Get the following program working.
- Enter at least 10 names of people that you know.
- What is wrong with this program? And why is it
doing that?
import java.util. public class Students
public static void main(String args)
String tempName ArrayList firstNames new
ArrayList() ArrayList lastNames new
ArrayList() tempNameGetData.getString("Ente
r last name") while(tempName.length()gt0)
lastNames.add(tempName)
tempNameGetData.getString("Enter first name")
firstNames.add(tempName)
tempNameGetData.getString("Enter next student
last name")
4Homework 3 - part 5, continued
if (! lastNames.isEmpty())
Collections.sort(lastNames)
Collections.sort(firstNames)
System.out.println("\n\nSTUDENTS")
Iterator x lastNames.iterator() Iterator
y firstNames.iterator() while
(x.hasNext()) y.hasNext()
System.out.println(y.next() " " x.next())
//end while //end if statement
//end main //end class