This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes java Collection question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java Collection question" Watch "java Collection question" New topic

java Collection question

Saathvik Reddy
Ranch Hand

Joined: Jun 03, 2005
Posts: 228

I have a collection which is like {obj1, null, obj3}. This collection is the result of a database query.
when i am trying to access the 2nd object(which is null) i am getting NPE. How can i filter the collection for null values?

Thanks in advance.
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11923

do you want to prevent null objects from going into the collection, or when the object is null, avoid getting the NPE?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Minh Tran

Joined: Jun 03, 2007
Posts: 19

SCJP 1.4, SCWCD 1.4<br />
Saathvik Reddy
Ranch Hand

Joined: Jun 03, 2005
Posts: 228
That was simple! Thanks a lot Minh.
wood burning stoves
subject: java Collection question
It's not a secret anymore!