• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to retrive only INTEGERS From List  RSS feed

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I WANT TO KNOW HOW TO RETRIEVE ONLY INTEGERS FROM A LIST , CONTAINS MANY ELEMENTS.
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like a rather strange thing to have to do. Real application or programming exercise?

Anyway, an Iterator will let you go through all the elements. The instanceof operator will let you test their types. The Iterator.remove() method will allow you to remove the ones you need.

Note that you cannot use the remove() method of the List, while iterating, as this will cause ConcurrentModificationException.
 
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your list is made of many types of objects and some of them are Integers use the instanceof operator to find out if the Object is an integer. If you want String types to be processed as integers when they hold numerals like "123" use the integer constructor that takes a String argument. If you dont get an exception (NumberFormatException) you are good.

Also please refrain from using all CAPS in your succeeding posts.
[ December 04, 2006: Message edited by: John Meyers ]
 
Jalli Venkat
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends ,
Thanks for your reply.

Thanking you
Venkat
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!