Java 8 Streams Java Java API
Interface:
java.util.stream.Stream
Method:
static <T> Stream<T> iterate(T seed,
UnaryOperator<T> f)
Returns an infinite sequential ordered Stream produced by iterative application of the provided UnaryOperator . The seed is the initial element of the iteration.
Examples
package com.logicbig.example.stream;
import java.util.stream.Stream;
public class IterateExample {
public static void main(String... args) { Stream<Integer> stream = Stream.iterate(0, i -> i + 1) .limit(10); stream.forEach(System.out::println); } }
Output0 1 2 3 4 5 6 7 8 9
@PostConstruct private void postConstruct () { Stream.iterate(1L, a -> a + 1) .limit(10) .forEach(this::createCustomer); }
private void createCustomer (Long id) { DataFactory df = new DataFactory(); Customer c = new Customer(); c.setName(df.getName()); c.setId(id); Address a = new Address(); a.setStreet(df.getNumberText(4) + " " + df.getStreetName()); a.setCity(df.getCity()); a.setCounty(df.getItem(Locale.getISOCountries())); a.setZipCode(df.getNumberText(5)); c.setAddress(a); customerMap.put(c.getId(), c); }
Original Post
|
|