Java Quiz 33 – ArrayList remove() method

What will be the output of following quiz ?

 

Quiz 33(ArrayList)

package com.topjavatutorial;

public class Employee {

  private int id;
  
  private String name;
  
  Employee(int id, String name){
    this.id = id;
    this.name = name;
  }
  
}


package com.topjavatutorial;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ArrayListRemoveDemo {

  public static void main(String[] args) {
    
    List<String> countries = new ArrayList<String>();
    
    countries.addAll(Arrays.asList("Australia","Canada","India","USA"));
            
    countries.remove(new String("USA"));
    
    System.out.print(countries.size());

    List<Employee> empList = new ArrayList<Employee>();
    
    empList.add(new Employee(1,"A"));
    empList.add(new Employee(1,"B"));
    empList.add(new Employee(1,"C"));
            
    empList.remove(new Employee(1,"A"));
    
    System.out.print(empList.size());
    
  }

}

© 2016, https:. All rights reserved. On republishing this post, you must provide link to original post

3 comments

  1. hey it was a great example to learn. Can you please explain how it works ?

    1. Hi,
      Please click on Start Quiz button and attempt the quiz for ArrayList remove methods. The correct answer with explanation will be provided after you submit your answer.

  2. […] Java Quiz 33 : Puzzle on removing arraylist elements […]

Leave a Reply.. code can be added in <code> </code> tags

%d bloggers like this: