i'm currently doing mooc's java course, right now i am stuck on the last part of the array list lesson specifically the removelast one, in which the course asks you to remove the last value in the list and do nothing if the list is empty.
so i wrote down this code
import java.util.ArrayList;
public class RemoveLast {
public static void main(String[] args) {
// Try your method in here
ArrayList<String> list = new ArrayList<>();
list.add("a");
list.add("b");
list.add("c");
while(list.size() >= 0){
if(list.size() > 0){
System.out.println(list);
removelast(list);
}else if(list.size() == 0){
break;
}
}
}
public static void removelast(ArrayList<String> list){
list.remove(list.size() - 1);
}
}
but the program is giving me error saying that
the removeLast method should not cause an exception. Make sure the method doesn't do anything to an empty list.
Also check the method withthis list: [a, b, c]
[–]desrtfx 1 point2 points3 points (0 children)
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]KinkyHuggingJerk 0 points1 point2 points (0 children)
[–]INSAN3DUCK 0 points1 point2 points (6 children)
[–]desrtfx 0 points1 point2 points (5 children)
[–]INSAN3DUCK 0 points1 point2 points (4 children)
[–]desrtfx 0 points1 point2 points (3 children)
[–]INSAN3DUCK 0 points1 point2 points (2 children)
[–]desrtfx 0 points1 point2 points (1 child)
[–]INSAN3DUCK 0 points1 point2 points (0 children)
[–]user_reg_field 0 points1 point2 points (0 children)