All Questions
22 questions
0
votes
3
answers
9k
views
How to replace for loop with streams in java
class Checker{
void CheckingNameFromDeptCode(LinkedList<Employee1> empObj, String deptID)
{
for (int i = 0; i < empObj.size(); i++) {
if (empObj....
0
votes
3
answers
535
views
How to iterate Object in stream while using Collectors.groupby()
I have one bean class Hotel in which data members are HotelName, HotelCity, HotelContact.
Now I want to save that data in Hashmap in a way where map Key should be City and all the hotel names should ...
0
votes
1
answer
362
views
Why do my ArrayList of Arraylist values change back after I set them? [closed]
I'm working with an ArrayList of Arraylists of Arraylists of ArrayLists, unfortunately. I'm very new to Java, so this could be a simple mistake on my part (I'm used to Perl). I'm troubleshooting some ...
3
votes
2
answers
295
views
Why does for(T t : this) work and what does it mean?
public abstract class MyAbstractSet<T> implements Iterable<T> {
...
// some code
...
method addElement(T t){
for (T t : this) {
//why does this work????
...
1
vote
1
answer
107
views
Rewrite using Java8 streams
Well, I wanted to understand if it is possible to rewrite below code using streams? If someone can explain why we can rule out streams here at first place.
for (int i=0;i<size; i++) {
int j = ...
11
votes
4
answers
1k
views
Collecting a collection of list based on similar index
I have a collection like :
List<List<Object>> firstList
I want to group together a similar list of pattern :
List<List<Object>> secondList
but grouped by indexes.
say
...
0
votes
0
answers
81
views
Iterate Map using forEach and keep track of index [duplicate]
Let's say we have a EnumMap in java and through the iteration using streams we need to use the key of the map, the value and the index. I have implemented as in the following example:
EnumMap<...
2
votes
1
answer
99
views
Need advise on iterating through a Java List<Map<String, String>>
I need advice on how to best iterate through a List<Map<String, String>> object for the following outcome:
The object holds data which was fetched from a sql database. Each Map entry ...
-3
votes
1
answer
1k
views
Java 8 Streams for List iteration
I have a HashMap that contains List<Dto> and List<List<String>>:
Map<List<Dto>, List<List<String>>> mapData = new HashMap();
and an Arraylist<Dto>.
I ...
1
vote
1
answer
3k
views
How to iterate over generic list
I have a class in that I take one list of generic type. Now I am trying to iterate over that list to get the value of that class. In getOrderAmount() method I trying to iterate.
@Document(collection =...
11
votes
3
answers
6k
views
Is use of AtomicInteger for indexing in Stream a legit way?
I would like to get an answer pointing out the reasons why the following idea described below on a very simple example is commonly considered bad and know its weaknesses.
I have a sentence of words ...
3
votes
3
answers
777
views
How to move to the next value in a loop when using Java 8 Stream API
When using external iteration over an java collectios we use keyword "continue" for move to the next value in a loop. What about in the case, when we use java stream API? Example:
List<User> ...
1
vote
2
answers
98
views
How to get the Collection using stream API
I am trying to access a list of string from a data structure which is having collection of collection. What I have tried yet is returning a list of collection,but I want a single list. Here is my code:...
5
votes
2
answers
835
views
What is the difference between Java8 container `for each` and Stream `for each` [duplicate]
I know we can use List.foreach
to traverse,and we can use List.stream.foreach to traverse too. I do not understand which is better to traverse in Java8.
1
vote
1
answer
479
views
How can I use two arrays to create a HashMap in Java 8? [duplicate]
I have two arrays of Strings. How can I loop through both arrays at once to create a HashMap<String, String> where the key is coming from first array and the value is coming from the second ...