Skip to content
Advertisement

Tag: collections

Collection cannot be converted to Object[]

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

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 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

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

Advertisement