M
M
Moiaposhta2020-10-28 19:16:00
Java
Moiaposhta, 2020-10-28 19:16:00

How to convert string with Java 8 lambda to 7?

Have Function

private void addAllOrderedStocksToList(List<Integer> list) {
        Iterator<Integer> amountIterator = data.getNumberOfOrderedStacks().iterator();
        Iterator<Integer> lengthIterator = data.getOrderedStackLengths().iterator();
       while (amountIterator.hasNext()) {
          int amount = amountIterator.next();
          int length = lengthIterator.next();
           IntStream.range(0, amount).forEach(x -> list.add(length));   
       }
}

The problem I'm having is on this line. I don't understand what she's doing at all.
IntStream.range(0, amount).forEach(x -> list.add(length));
Can someone help me convert it to Java 7.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2020-10-28
@Moiaposhta

Java 7 doesn't have Stream API. Rewrite the for loop from zero to amount, and in the body of the loop add the length value to the list list.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question