Menu
Question Index
...

What will be the output of the following program?

import java.util.ArrayList;

public class DeleteFailedStudents {
    public static void main(String[] args) {
        ArrayList students = new ArrayList();
        students.add(new Student("Raja", 23));
        students.add(new Student("Rajesh", 87));
        students.add(new Student("Rajani", 50));
        students.add(new Student("Rajanna", 35));
        students.add(new Student("Rajanikanth", 90));
        deleteFailedStudents(students);
        System.out.println(students);
    }
    public static void deleteFailedStudents(ArrayList<Student> students) {
        for (Student student : students) {
            if (student.marks < 35) {
                students.remove(student);
            }
        }
    }
}
class Student {
    String name; int marks;
    public Student(String name, int marks) { this.name = name; this.marks = marks; }
    public String toString() { return name + "-" + marks; }
}


[Rajesh-87, Rajani-50, Rajanna-35, Rajanikanth-90]
[Rajesh-87, Rajani-50, Rajanikanth-90]
[Rajesh-87, Rajani-50, Rajanna-35]
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java ArrayList

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App