Java-stream Questions
Ad
Java group by custom variable and return same object
I want to count number of duplicate in my list by custom variable (myhash) map<personhash, long> result = list.stream()
No suitable method found for collect/reduce - Can't sum a list of Integers with stream()
In the input, i have a list of integers and strings together. the first stream works fine, the second stream works until the filter, i
Check if one List<String> contains specific string from another list
I have a list of emails of list<string> type, and another one of keywords also list<string>. each email
Merge Person objects with similar attributes into a single Map Entry
Person.java class person{ string name; integer age; integer salary; //...getter..setter } list
get average salary with Java stream api;
How can i get the average salary of company employees whose salary is more than salarylimit? i think first i need to get a list of all salaries
Copy All the elements/object of one list N times to new list. Using java 8 stream
Copy all the elements of one list n times in a new list. i have list of fruits which i want to iterate to n times and add all the value to
Refactoring a nested loop into Java 8 streams collecting the outer objects
I have a loop which does what i want - it adds objects of type a to the results list: arraylist<a>
How to use forEach() method in Java 8 loop n+1 time but my list size is random like n, n-1, n-2
How to use foreach() method in java 8 loop n time but my list size is always random like n-1, n-2, etc.... if list size
Map of List: Sum all the values of the list class
I have this class public car(colour colour, int passengers) { this.colour = colour; this.passengers = passengers; }
Map<String, List<String, Object>> add new list entry when key exists
Let's say i got map<id, object> when looping over the entries via .entryset().stream() i want to map it to
Ad
Is it possible to use a Stream to collect an Object into a hashmap, rather than casting?
I have a map mymap of type <string, object> which looks like: ( "header", "a string
What to do if i have 1000 column in this given example in java 8
Aftere load data from csv file then list look like below and first column unique id and rest 999 have data value. i want to sum duplicate records
Is it possible to calculate values in a stream based on themselves
If i have a java stream of e.g. numbers, is it possible to calculate e.g. the sums up to that number (by adding the number to the
Using Streams on a map and finding/replacing value
I'm new to streams and i am trying to filter through this map for the first true value in a key/value pair, then i want to return the string key,
Java 8 - Replace each row with GroupBy sum
I have class data which have 4 fields and have list of values then i want replace each row groupby year and sum value for same year using java 8
How to neglect objects during stream grouping or partitioning?
It is possible to neglect some elements during collectors.groupingby or collectors.partitioningby? of course i
Java 11 Select a method to apply on a stream based on enum value
I have the following enum. public enum aggregationtype { min, max, average } let's assume that i have
Return city in which most people live - stream()
I have a class called person (name,surname,city,age) and i added to it persons. i have to find the city that lives the most people - in
How to iterate over lambda functions in Java
I was able to do it in python and my python code is: signs = {"+" : lambda a, b : a + b, "-" : lambda a, b : a - b} a = 5 b = 3
Why my stream calling cannot be chained
I have a function: private hashmap<string,string> getproperties(httpservletrequest request) {
Implementation for map-reduce with java streams
I'm trying to implement map-reduce paradigm this 1 command in java stream. for example, i have a list of orders for various customers, each order
Ad
Grouping by the inner collection element type in collection
I have list<shop> shops; class shop { private long id; private string name; private list<supplier>
java enforcing the return type to generic types instead of Object types for constructing map using collectors and streams
I'm trying to construct map<string, graphnode<character>> from list<pair<graphnode<character>,
Java 8 iterate through list and store in Map
List<string> list =new arraylist<>(); list.add("abcd"); list.add("afsd"); list.add("addd"); map<string,
java generated parallel IntStream(and other stream) issues
Public static void main(string[] args) throws throwable { atomicinteger i = new atomicinteger(); intstream .generate(
How to modify a field in each element of list in java 8 using stream
I have the following classes: class employee { private string name; private list<address> addresses; //...
Ending an "infinite" stream when certain conditions are met
I'm trying to pull data from a rest-style web-service which delivers content in pages. the only way i can know that i've reached the end
java 8 stream for sorting a list of objects based on particular field
I have a scenario to sort the objects based on timestamp. the classes are as follows: class employee { private string name;
call method with stream parameter from stream itself
Assume we have the following situation collection<sometype> somecollection = .. stream<sometype> stream =
When to use specialised stream methods over methods in the Collectors class or vice versa?
We can see that the collectors
Java Stream API map argument
I have some misunderstanding about java 8 static method references. the following is a correct statement: stream.of("aaa",
What is the difference between Comparator::reverseOrder and Comparator.reverseOrder() when used in sorted method of stream
What is the difference between comparator::reverseorder and comparator.reverseorder() when used in sorted method of
Ad
Java 8 stream groupBy pojo
I have a collection of pojos: public class foo { string name; string date; int count; } i need to
Easier way to reverse a comparator created by a static method (Functional Interface) inline?
Since comparator<t> is a functional interface, i can do this comparator<instant> instantcomparator =
how to convert List<Map<String, String>> to List<Map<String, Map<String, String>>>
Can some on tell me how to convert list<map<string, string>> to list<map<string, map<string,
Aggregating values in a list by multiple group by and calculating percentage of distribution in java 8
I have use case like this where i need to aggregate values in a list by multiple group by but then calculate percentage of distribution of each of
Java8 remove keys from List<Map<String, Object>>
I have a list<map<string, object>> and i need to remove the nested key = "age" if exists and return the list of map. how can
How to convert List<AnyClassObject> to List<Map<String, String>> using Stream in java 8?
I have a list, i need to convert it to list<map<string, string>>. for e.g. consider below scenario: public class
get list of objects distinct by all fields
How can i get all the distinct objects in a list using java 8 streams? it has to compare all the fields of objects with each other. for example
Trying to reverse my stream in ascending order - Java 8
This idea behind this code is that it reads the data from three .csv files w/ keys organized by year, and retrieves the sum of the
java streams: accumulated collector
Currently, that's my code: iterable<practitioner> referencedpractitioners =
How to use Java Streams to fetch Strings from an ArrayList of HashMaps
I have a data structure - arraylist> and this is what i need to do - arraylist<hashmap<string, string>> optmaplist;
How to use Java stream map with filters and optional?
Basically what i want to do is following code(i will get system param and will check if it is not null then if the current system on the code is
Ad
several arrayList to single List
I'm working on an app that deals with animals by category. public class animal { private long id; private
How can I correctly use the stream map() in this use case involving the conversion of an entity class instance into a DTO instance?
I am working on a spring boot application and i am trying to use a more modern (java 8+ constructs) but i am finding some difficulties trying to
How to concatenate all lists of objects (containing some text) within one big list through the means of stream()
I got: a list of lists of textinfo objects. each textinfo object contains a piece of text and a tostring override method to return the text. by
How to get object field for max value in another field in grouped by one more field?
I have list of entities that looks like this: class history { public string code; public integer version; public
Sort subgroups of lines in text file
I have a server property file called filelist.txt. this filelist contains a list of files which are arranged in groups based upon
Comparing elements within Stream
Suppose i have a list of item and i transform it into list of another type using stream. suppose also that the original itemlist is
errorNoSuchMethodError: java.util.stream.Stream.toList()Ljava/util/List only from CLI, fine from eclipse
I'm trying to run windows cli command from java. i got an issue when parsing results but only when running the code as a runnable jar from cli,
Compare two lists that are encapsulated in a custom object inside list
I have following code: public class person { private string id; private string name; private list<house> house }
Why does sendAsync HttpClient work sequentially if I'm not do collect inbetween?
During doing a tutorial about jdk11 httpclient, using a https://httpstat.us/500?sleep=1000 endpoint which is returning
java replaceAll with java lambda or java stream (from String[])
I want replace all .ini by empty value (replaceall(".ini", "") but with java lambda or java stream.
Java Using Stream and Lambda Expressions Instead of Iterator
I have an assignment for my computer science course and our instructor wants us to use stream and lambda expressions for an iterator. i haven't
Ad
What is the best way to programmatically assert a WebFlux stream?
So let us say we have something like: public class someservice { ... public flux<string> getstringsfromwebserver() { return
How to find maximum form custom object of objects using java 8
I have list of object (please ignore syntax i have changed names, the code compiles well) list<employees>
Stream API, is there way to iterate descending using instream.range?
For example, instream.range(0,10) - is iterating from 0 index to 10. instream.range(10,0) - but from 10 to 0 is
Agregate nested list with Stream api
Let's say i have a shelf class and each shelf has multiple books. public class shelf{
Get values of a property from array of objects
I have an list of objects: [class retaileritemvariant { sku: 008884303996 isavailable: true price: 70.0 }, class
Stream / Reduce a series of functions applied to an input value with bound variables in Java
How does one go about rewriting this loop using a stream. private final list<regionspecificvalidator> validators; public item
How can I map all words in the description of a Film to all films' names that contain the word in their description fast?
I have a list<films> films, where each film has int id and string description. my task is to map each
How to sort the list of object what contains the list that contain also the list of object in Java?
I have the list of object of the "mainclass" class that contains the list of objects of the "question" class, that contains
How to multiply key * value in Map in Java?
I have this class: class product { public double price; public product(double price) { this.price = price; } }
How to get the average duration for each category having films using stream API java
I have a class film with the following fields string name; double duration; collection<string> categories;
Stream<String> conversion to Stream<Character>
I am trying to read from a file, count the frequency of each letter, and print the results. uppercase letters should be treated as their
Ad
java 8 local variable in stream.foreach
I would like to use local variables in lambda functions but i get error: please see the 1. and 2. points in the code. class foo {
Combine two streams into one to return a Pair
I have a list of objects consisting of only two fields. i want to convert it into pair for easy access to fields for
Java: Group By then Map
I have a stream of events public class event { location location; double turnout; //... other fields
How to create Flux from Mono
I have a mono a. the object a contains two lists. i want to create direct two flux. is this possible without block()?
Collectors.toUnmodifiableList in java-10
How do you create an unmodifiable list/set/map with collectors.tolist/toset/tomap, since tolist (and the
XXXSummaryStatistics new constructor in java-10
I see that java-10 adds a constructor for intsummarystatistics (longsummarystatistics and
What is the meaning of "pipelined" in Java Streams?
In the java stream api definition, it says "stream api is used to process collections of objects. a stream is a sequence of objects that
File download error only in file name with Comma
In my file download api case an error like this. org.apache.catalina.connector.clientabortexception: java.io.ioexception: broken
Group by n fields in Java using stream API
Need to group list<object> based upon n property fields, this fields are decided at run time. how can i achieve this ?
Create map of segregated values from two lists in stream
I'm trying to create map of two lists. first list is used for keys and second to segregate and assign values, wherein situation, where there are
merge indexes of lists in a list if first index value is same in java
I am looking to merge the lists in a list if the 1st index match in java8. i have a list of lists [[abc, 1.0, 4.0, 4.0], [abc, 2.0,
Ad
Custom Tree Node search algorithm in java
I am trying to search the child nodes based on the search query. i also need to keep their parents in the list. i am facing difficulty iterating
Convert List of List of Elements to Map < K, List<V>>
I have following structure. request { list<param> paramlist; date startdate; date enddate; } param { string
How to get the list of latested objects from a list
I have a list of objects (instance of class a): class a { private string name; private date createddate; } list [ a ("a",
Return only true predicates in Java stream
I have the following method: public boolean ismsgok(string msg) {...} i want to call this method here:
Convert IntStream to int
I have never used streams in java before and am now trying to test how to accomplish simple examples with stream. i want to return a
Replace nested for loops with parallel stream - Java
I'm working on improving the speed of a program where performance is critical. currently it fails to process large data sets. there are many
Is Stream.of(item).collect(Collectors.toSomeCollection()) faster than new SomeCollection(Arrays.asList(item))?
Java 8 provides stream.of(item).collect(collectors.tosomecollection()) e.g.
Java 8 Streams groupingBy collector
How would i get this data structure using java 8 api? this is my object structure: class a { b b; public a(b b)
Java8: About order of Map elements returned by Collectors.groupingBy
Would like to seek for advice on the following piece of code modified from an example came across. i was wondering whether the output
Remove empty Optionals from Stream using StreamEx
I'm searching for an elegant way to stream only non-empty optional entries using the streamex library. or the standard library, if
Java8 Extract multiple fields from a class object using streams
I have a list of class a objects with multiple fields including number1 &
Ad
Blog Categories
Ad