I keep a list of Strings in SQL as @ElementCollection, my main usage is similar to a Queue: fetch it from the database run some calculations remove the first element and insert a new element to the end of the list: this.measurements.remove(0); this.measurements.add(measurement); save it to the database The problem with the current implementation is that removing the first element
Tag: collections
Call custom static functions from filter and map in Java 8 – stream
I want to call method name nameStartingWithPrefix() which is inside filter and its definition will be in Filter class. All ArrayList describes in main(), but the list is not passed as in an argument, how can I call in List of names inside Filter.nameStartingWithPrefix(). Syntax is given like: names is name of ArrayList which is inside main() Below is code
How to create a Queue which accepts any Datatype?
How to insert both String’s and Integers in the same Queue ? Please look at the below program, I have created two objects (q, q1). Can we insert strings and integers in one Queue? import java.util.*;…
Java Array List – Facing issue while taking values from user, but unknowingly program terminating
I am trying to take values from user in ArrayList, I can take input for the size of ArrayList, But, when I am trying to add elements, the program is being terminating. Here is my code Answer You must use .readLine() also inside the loop: Running result:
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
Transform List into Map using only two keys and odd or even list indexes as values – Java 8 Stream
I would like to transform list into map using as key values only two string values. Then as values just list of strings containing elements from odd or even index positions from input list. Here is old fashion code: How to transform this code into Java 8 using streams to get this result? My current messy attempt require modifying elements
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