Skip to content
Advertisement

Tag: collections

java.util.Map values() method performance

I have a map like this with several million entries: I need to get list of values, which could be done by calling java.util.Map values() method. Is Collection of values created every time I call values() method or is it pre-computed from performance perspective? As my Map has several millions elements, I do not want to create new list object

understanding comparator in Collections.max

Can somebody please explain what the following lines of code mean?. I had a hard time understanding the Comparator part.I tried googling but all of them were too complex for me to understand. Could somebody please explain it in simpler way? Answer The max method returns the element that is considered the “biggest” in the collection. In this case, you

List view of concatenated lists

I want to create a list view that consists of the concatenation of a number of other lists. Example: What kind of technique and or pattern can I use in Java to fulfill these requirements? Details I want the concatenation to be lazy. (That’s the meaning of “view” in this context.) I want change to the component lists the reflect

clear all values of hashmap except two key/value pair

I have a HashMap with hundred of key/value pairs. Now I have to delete all key/values except 2 key/value. I have use this way : But java 8 introduced removeIf() for these kind of condition. How can I solve this problem with removeIf() method ? Answer You’ll need to it like this : It will iterate over the keys and

“Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements”

Good morning Stackoverflow, I have the problem that it gives me the error: Failed to create sessionFactory object.org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements: nl.scalda.pasimo.model.employeemanagement.EducationTeam.coachGroups Do you know why? Answer The Exception is straightforward and says : Illegal attempt to map a non collection as a @OneToMany, @ManyToMany or @CollectionOfElements, so the cause

Advertisement