Questions tagged [java-stream]
Use this tag for questions related to the use of the Stream API. It was introduced in Java 8 and supports functional-style operations on streams of values, such as filter-map-reduce pipelines on collections. DO NOT use this tag for questions about Java InputStreams or OutputStreams.
java-stream
11,837
questions
-1
votes
2
answers
35
views
How to assign a value obtained by Stream to String variable in Java? [duplicate]
This is related to automation testing using Selenium and Java.
I am getting all elements of a column in a List<WebElement>.
After this, I want to get the first element of the above list using ...
-2
votes
1
answer
68
views
Remove item from list when no matching element found in sub-sub-sub nested collections [closed]
Is there a way to remove an item from the first list (versions) if no item meeting the condition is found.
here's the condition:
s -> s.getId().equals(identifier) && s.getStatus().equals(&...
0
votes
1
answer
79
views
Create a Map<Long, CustomObject> , iterating a List<CustomObject>
I've a list of Order which I am fetching from some third part api.
List<Order> orders = fromApi(orderId);
Here is the Order class:
class Order{
Long orderId;
Product product
}
...
4
votes
1
answer
83
views
Use collect to return List<particular type> instead of List<Object>
I want to collect List<TestClone>, but looks like .collect() returns only List<Object>. Is there a way I can get List<TestClone>?
I know .toArray() is there, but want an ArrayList.
...
2
votes
2
answers
75
views
Java 8 compare list of integer and list of Object
I have input of Ids
List<Integer> idList = List.of(100, 101, 102, 103, 104);
from DB i got list of Objects
@Getter
@Builder
public class CustomObject {
private int id;
}
List<...
0
votes
1
answer
74
views
change value in inner map with stream
I have this kind of map Map<String, Object> , As you can see there is a inner map "token" and inside this map, there is inner map "tokeninfo":
{
"id": "...
0
votes
1
answer
68
views
can I convert List of String into single String using java 8 streams [duplicate]
I have written a below code using java.
List<String> list = new ArrayList<String>();
list.add("book1");
list.add("book2");
list.add("book3");
list.add("...
0
votes
1
answer
83
views
How to combine multiple Collections (Queue or List) element by element?
I have 3 queues of records (of idential size and datetime order) and want to combine them record by record.
It is similar to below:
record BuyOrder(String date, String product, double buyPx) {};
...
0
votes
2
answers
93
views
Java 8 Streams API grouping by two fields and return updated Collection
I have java custom class i.e Employee having below fields,
public class Employee {
private String name;
private String dept;
private Integer age;
private Double salary;
}
public ...
-1
votes
1
answer
74
views
Java Iterate list inside list
I have a method resolver.calculateForDay(day, uuid)
Dyas it is Enum and list of uuid.
public enum DaysOfWeekEnum {
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
...
0
votes
4
answers
131
views
Sort Map using java streams
How to sort a map with the key first and sort the values as well.
Map<String, List<String>> myMap = new HashMap<>();
myMap.put("Apple", Arrays.asList("iphone", &...
0
votes
1
answer
61
views
why are the results of the 2 streams different? [duplicate]
The Stream API supports lazy operations, so I understand that it calculates vertically.
However, the results are different depending on the location of the limit method. Why does the operation ...
-1
votes
2
answers
92
views
java lambda Transform a map<K, List<MyObject>> to map<K, List<String>>
I need to transform a map:
Map<String, List<Employee>> departmentWiseEmployees
to
Map<String, List<String>> departmentWiseEmployeeNames
...using Java lambda.
Mostly I see a 2nd ...
-5
votes
2
answers
79
views
Stream map returns null instead of stream [duplicate]
There is a list of elements of the Event class.
@Data
@AllArgsConstructor
public class Event {
private Long id;
private String nameRu;
private String nameEn;
}
I want to get value of one ...
0
votes
1
answer
45
views
Validate all my model elements has same value in java [duplicate]
I have Model Class
public class MyObject {
private String name;
private String location;
//getters and setters
}
List<MyObject> models = new ArrayList<>();
How can I validate ...