Skip to content
Advertisement

Tag: collections

Java : list that contains unique elements in order

Is there a list type in java that stores objects in ascending order and not adds if this object is previously added. I know java maps can do that but I wonder if there is a list type that does what I want. Otherwise I have to override contains, equalsTo and add methods,right? Answer So you need a list containing

Bounded, auto-discarding, non-blocking, concurrent collection

I’m looking for a collection that: is a Deque/List – i.e. supports inserting elements at “the top” (newest items go to the top) – deque.addFirst(..) / list.add(0, ..). It could be a Queue, but the iteration order should be reverse – i.e. the most recently added items should come first. is bounded – i.e. has a limit of 20 items

What type of data structure should I use to hold table rows?

I’m new to Java and just getting into querying databases. So far I have my results in a ResultSetMetaData. I’m think that for each row in the dataset I should add it to some form of collection? Can anyone tell me the best practice for this? Thanks, Jonesy Answer Usually we have a class with fields that correspond to a

Shortcut for adding to List in a HashMap

I often have a need to take a list of objects and group them into a Map based on a value contained in the object. Eg. take a list of Users and group by Country. My code for this usually looks like: However I can’t help thinking that this is awkward and some guru has a better approach. The closest

Advertisement