Skip to content
Advertisement

Tag: collections

Mapping pair of elements into one with Stream IPA

So I’m wondering what is the best solution to the following problem: I have a list of items (a custom class) in a java collection ex Each item in the collection however has a corresponding logical pair also in the collection (so the pair’s are not necessarily following each other by index in the collection) I have a helper method

Rearrange substrings using two criteria [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 12 months ago. Improve this question Given a String: I need to sort its substrings first by numbers (in descending order) and then by letters, so

Why list.contains(null) throwing null pointer exception?

I have List<Long> countriesList which contains Long values which are country ids. Now I am iterating over some List<UserRequests> list by using streams. I tried to debug by evaluating individual statements. I have made sure countriesList have some data First part CollectionUtils.isNotEmpty(countriesList) is returning true. userRequest is also not null but userRequest.getCountryId() is null. And when I evaluated countriesList.contains(userRequest.getCountryId()), I

remove (and count) duplicates from a list

Is it possible to iterate between two iterators of a same list and remove an item within the nested iterator? Version 1 (does not work): } I get a java.util.ConcurrentModificationException, because I modify an element within the same iterator.. I can solve this issue by using another list removableItems and put those items in it: Version 2 (works): Is there

Map a List to DTO inside map – java

I have such collection: Map<Integer, List<MyObject>> collection I would like to map the whole list of MyObject to MyObjectDTO and return the whole map with the mapped list. So return will be: Map<Integer, List<MyObjectDto>> collectionWithDtos What is the easiest and quickest way? I’ve checked a couple of ways with streams but none of that produced results as I expected. Thanks

Create and find highest value in subarraylist

I have an Arraylist of the Cells from an Excel sheet. I want to create subarraylists of size 50 from the Arraylist of Cells I actually have, beginning from the index of 1590 and ending with size()-700. I want to get the highest number from every subarraylist and put it in the new Arraylist. in the new Arraylist there should

Create a merged map with list of maps

I’m new to java so seeking help from experts. any help would be much appreciated, and a scope for me to learn new things. I want to create a List of maps(resultList) from a another list of maps(list) where a single map(keys) contains values which are keys to the list of maps(map1, map2, map3 … So on). Like below example

Advertisement