The Artima Developer Community
Sponsored Link

Java Buzz Forum
How to remove elements from ArrayList in Java?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
How to remove elements from ArrayList in Java? Posted: Jun 12, 2015 10:46 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: How to remove elements from ArrayList in Java?
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
In this Java ArrayList tutorial, you will learn how to remove elements from ArrayList in Java. There are actually two methods to remove an existing element from ArrayList, first by using remove(int index) method, which removes elements with given index, remember index starts with zero in ArrayList. So a call to remove(2) in an ArrayList of {"one", "two", "three"} will remove 3rd element which is "three". Second method to remove element is remove(Object obj), which removes given object from ArrayList. For example a call to remove("two") will remove the second element form ArrayList. Though you should remember to use Iterator or ListIterator remove() method to delete elements while iterating, using ArrayList's remove methods in that case will throw ConcurrentModificationException in Java. Things get little complicated when you are working with ArrayList of integral numbers e.g. ArrayList of integers. If your list contains numbers which are same as indexes e.g. then a call to remove(int index) can be confused with a call to remove(Object obj), for example, if you have an ArrayList containing {1, 2, 3} then a call to remove(2) is ambiguous, because it could be interpreted a call to remove 2, which is second element or a call to remove element at index 2, which is actually 3. If you want to learn more about Collection classes, I suggest you to take a look at one of the all time classic book, Java Generics and Collection. This is the book I refer to refresh my knowledge on the topic.
Read more »

Read: How to remove elements from ArrayList in Java?

Topic: Composable Cloud At HP Previous Topic   Next Topic Topic: How to reverse words in String Java? [Solution]

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use