Computer Science › Lists
Which of the following is NOT a difference between the Array class and the ArrayList class in Java?
Consider the following code:
public static class Circle {
private double radius;
public Circle(double r) {
radius = r;
}
public double getArea() {
return radius * radius * Math.PI;
}
}
public static void main(String\[\] args) {
ArrayList
for(int i = 0; i < 10; i++) {
circles.add(new Circle(i + 4 * 2));
}
}
Which of the following represents code for iterating through the list circles in order to output the areas of the circles contained therein?
Consider the code below:
String\[\] db = {"Harvey","Plutarch","Frege","Radulphus"};
ArrayList
for(int i = 0; i < 12; i++) {
names.add(db\[i % db.length\]);
}
for(int i = 0; i < 12; i++) {
if(names.get(i).equals("Frege")) {
names.remove(i);
}
}
What is the bug in the code above?
Which of the following is NOT a valid declaration for an ArrayList?
Write a program that iterates through this data structure and prints the data (choose the best answer):
List<List<String>> listOflistOfStrings = new ArrayList<ArrayList<String>>();
Consider the code below:
ArrayList
myPhilosophers.add("Frege");
myPhilosophers.add("Husserl");
myPhilosophers.add("Hegel");
myPhilosophers.add("Bill");
myPhilosophers.add("Frederick");
for(int i = 0; i < myPhilosophers.size(); i++) {
String s = myPhilosophers.get(i);
if(s.charAt(0) >= 'H' || s.charAt(3) < 'd') {
myPhilosophers.set(i, s.toUpperCase());
}
}
System.out.println(myPhilosophers);
What is the output for the code above?