Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to remove item from ArrayList

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 299
    Comment on it

    The below example will help you to remove an Arraylist item using the element index. To remove an item from an arrayList I have used Object remove (int index) method. This method returns a reference to the item that was removed. You can see below program it will clearly describe you how to remove item from ArrayList. 

    public class RemoveItem{
        public static void main(String[]args){
            ArrayList arrayList = new ArrayList();
            arrayList.add("item_1");
             arrayList.add("item_2");
              arrayList.add("item_3");
               arrayList.add("item_4");
          
          //remove an element from the specified index of ArrayList use Object remove(int index)method.
    
          Object obj =arrayList.remove(3);
          System.out.print(obj+"is removed frok ArrayList");
          System.out.println("Items in ArrayList :");
          for(int i=0;i<arrayList.size();i++)
            System.out.println(arrayList.get(i));
    
        }
    }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: