Category "collections"

Why do I need Comparable for PriorityQueue?

I'm learning about Queue Collection and I don't understand why do I need to implement Comparable interface if I use PriorityQueue? I have used Comparable and Co

How to remove an element from a Set inside a Page of items based on a Condition using Java 8

I have a Page of Farmers coming from a JPA repository call findAll method. Each Farmer consists of a Set of Farms which are also coming in the repository call l

Get Only Values from a Map to an array

I want to get values of a map and store inside a string array in typescript. myMap= [0:'Mohit',1:'Balesh',2:'Jatin']; arr[]; Expected Result arr['Mohit','Bal

Java collection like c# KeyedColllection<TKey,TItem>

Is there a Java collection that has the same behavior as the c# abstract KeyedCollection class (that is items can be retrieved by both key and index)? I have l

java.lang.NoClassDefFoundError: org/springframework/util/MultiValueMap

I am using Spring-core 3.2 jar but I am getting error as "java.lang.NoClassDefFoundError: org/springframework/util/MultiValueMap". MultiValueMap<

How to pretty print a complex Java object (e.g. with fields that are collections of objects)? [closed]

I'm looking for a library function (ideally from a commonly used framework e.g. Spring, Guava, Apache Commons etc.) that will nicely print the

How to add items to a list of lists

I aim to print a list of lists containing entry and exit times in the 24 hour decimal format from the "AM"-"PM" String format input by the user as a String arra

How to write a method that takes in a List of Integer, Float, Double and calculate the average?

I am trying to write a method that takes in a list of numeric values - eg List<Integer>, List<Float>, List<Double> etc - and give me the avera

How to write a method that takes in a List of Integer, Float, Double and calculate the average?

I am trying to write a method that takes in a list of numeric values - eg List<Integer>, List<Float>, List<Double> etc - and give me the avera

Generic Method to Flatten a Collection of Nested Objects into a DataTable?

I have a list of objects, which in turn contain nested lists of further objects. I would like to flatten the object graph into a DataTable. I found code which t

Can list comprehensions make groups?

I have a list that looks like [(1,2,5),(2,10,13),(5,24,56),(1,8,10),(2,3,11)] How can I produce a dictionary by grouping by first element of tuples and find

Property Type Does Not Exist - MongoDB WithId<Document>

Using: ts-node: 10.7.0 MongoDB: 4.4.1 GraphQL: 16.3 I am trying to get a response back from a mongo db request. The request is successfully coming back, but typ

Merge Map<String, List<String> Java 8 Stream

I would like to merge two Map with JAVA 8 Stream: Map<String, List<String>> mapGlobal = new HashMap<String, List<String>>(); Map<Str

HashMap with List of Objects as a Key

in HashMap when I pass List of Objects as Key I get different results. List<NewClass> list1 = new ArrayList<>(); List<NewClass> list2 = new Ar

Java Stream: divide into two lists by boolean predicate

I have a list of employees. They have isActive boolean field. I would like to divide employees into two lists: activeEmployees and formerEmployees. Is it possib

How to determine if a type is a type of collection?

I am trying to determine if a runtime type is some sort of collection type. What I have below works, but it seems strange that I have to name the types that I b

Create and loop through collection subset of controls

Im making a small vb.net windows form application in which I have 4 ComboBoxes. I would like to add the ComboBoxes to a collection and be able to loop through t

Is there a way to filter out null Any? values in Kotlin Map?

I'm trying to think of a function that would allow a Map<String, Any?> object to be treated as Map<String,Any> through type inference through applyi

Clone a List, Map or Set in Dart

Coming from a Java background: what is the recommended way to "clone" a Dart List, Map and Set?

Return new collection without modifying original collection

I have a Laravel collection and I want to modify one of its property value to negative integer. For this I am using the collection map method but it also modify