points.remove(null) makes a call to remove(Object).
ArrayList class provides two overloaded remove() methods.
remove(int index): Accepts the index of the object to be removed
remove(Object obj): Accepts the object to be removed
The right answer is the letter E, because the number 1 is added in the second line of the list, but the list indexes from 0, so the 1 is in position zero and the removal done in line 7 removes the data in position 1 of the list which is 2. Remembering that you cannot give the NullPointer exception because lists can print null if it is inserted in one of the positions of the list, it would only give NullPointer exception if the list was empty. If you have any doubts, I'll also test the code, feel free:
public static void main(String[] args) {
ArrayList<Integer> points = new ArrayList<>();
points.add(1);
points.add(2);
points.add(3);
points.add(4);
points.add(null);
points.remove(1);
points.remove(null);
System.out.println(points);
}
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Sreeni_A
5 months, 2 weeks agoSreeni_A
5 months, 2 weeks agoVicky_65
10 months agoCreazyyyyGirl
10 months, 4 weeks agoRajeevkuamr
1 year agoakbiyik
1 year, 2 months agocarloswork
1 year, 2 months agokkaayyyy
1 year, 3 months agoiSnover
1 year, 4 months agopraroopgupta
1 year, 4 months ago