• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get a perticular Object in a collections with out comparing indivisually  RSS feed

 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All

As we know in collections we are storing Objects of different types and i want to get the Object of perticular type with out iterating the collection and comparing is it possible and i tried using Collections class if there is a solution give me a hint

 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't without a Map, so perhaps you want to switch to one.
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds odd design, wanting a collection of assorted types, then extracting objects by type. Why do you need it?
 
Ulrika Tingle
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
santhosh.R gowda wrote:
As we know in collections we are storing Objects of different types and i want to get the Object of perticular type with out iterating the collection and comparing is it possible and i tried using Collections class if there is a solution give me a hint


It's hard to know what you want to do.

It's not so that we store objects of different types in collections. It's almost always so that we store objects of the same type in a collection and we use generics to declare the collection to store objects of one particular type only.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!