Need help with a problem for a class! So I have created an array of names that gets passed to a method named runA in the class Proj04Runner. I need to create a TreeSet of these names to put them in naturally ascending order with no repeating values. However when I run my code, I get an error telling me
Tag: collections
Merge an List of Object and an Object to a new array in Java [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 10 months ago. Improve this question I have List<BigInteger> sample1 = Lists.newArrayList(BIGINTEGER1, BIGINTEGER2,BIGINTEGER3); I have to create new List sample2 with one more value BIGINTEGER4 along with sample1 list: How can
Merging instances of objects in a list by attribute
I have an object Person which has firstName, lastName and email I have a list of Person where there are potentially multiple Persons of the same firstName and lastName and I want to merge these by their email address with a delimiter. i.e. Person A = Person B = And I want these to be merged into So as to
incompatible types: no instance(s) of type variable(s) F,T exist so that java.util.Collection conforms to java.util.Set<java.lang.Long
I am trying to convert the list of ComplexItem to a list of their corresponding IDs Long. But getting the above error which doesn’t go even after typecasting the getCollection() call with (Collection<ComplexItem>) Answer There’s no reason to expect that the result of Collections2.transform, which is a Collection, will be magically transformed to a Set. This is the reason for
Sort collection according to user custom input by single or multiple attributes
I have collection of Item object and the class Item is as follows -> Now, I want to sort according to the user input. User can sort it according to his choice like brand, price or publishedDate and even with the multiple parameters. Like brand and price or price and publishedDate. I have seen Comparator to sort by multiple parameters
Sort List of Values in a Map in descending order
I have a Map with List of Doubles. unsorted map contents: {A=[0.02, 0.03], B=[0.0, 0.01], C=[0.01, 0.0], D=[0.05, 1.03], E=[1.01, 0.03]} I need to sort in descending order for List(0). I have tried the below logic but its sorting in ascending order. Actual output: {B=[0.0, 0.01], C=[0.01, 0.0], A=[0.02, 0.03], D=[0.05, 1.03], E=[1.01, 0.03]} Expected output: {E=[1.01, 0.03], D=[0.05, 1.03],
add element to limited size list
I have the following method which adds an element to a size limited ArrayList. If the size of the ArrayList exceeds, previous elements are removed (like FIFO = “first in first out”) (version 1): The “version 1”-method works. However, I wanted to improve this method by using subList (version 2): Both methods works. However, I want to know if “version
Duplicate elements being added in a set after I change the value after insertion
I have a set with two distinct objects added to it. After insertion, I change one of the objects in such a way that both the objects are equal (as verified by the overridden equals method in object class). At this point in time I have two duplicate elements in a set. Now I try to add these two duplicate
How can I accept an argument list in a constructor and add it to a collection in Java?
I’m trying to make a constructor that would accept any number of variables of class “Item” as a variable argument list and add them to appropriate collection. What would be the best way to go about it? My code so far: Answer Item… args should be fine.. You can then just do this … instead of the static items block.
Combine two lists by ID
I have two lists of objects with contents that look like this: I can’t come up with anything good to “merge” these two lists overriding the nulls. The ideal end result would be: I’ve been looking into Kotlin collections to see if there’s anything that would help me get closer to this but I have only been able to do