Tag: java feature


  • Java Streams API

    A Stream in Java can be defined as a sequence of elements from a source. The source of elements here refers to a Collection or Array that provides data to the Stream. Java streams are designed in such a way that most of the stream operations (called intermediate operations) return a Stream. This helps to create a chain of stream operations. This is…

  • Java 11 | toArray(intFunction)

    Stream toArray(IntFunction generator) example Description Stream toArray(IntFunction<A[]> generator) returns an array containing the elements of this stream, using the provided generator function. import java.util.List; import java.time.LocalDate; import java.time.Month; import java.util.Arrays; public class Main { public static void main(String[] args) { List<Employee> persons = Employee.persons(); Employee[] men = persons.stream() .filter(p -> p.getGender() ==Gender.MALE) .toArray(Employee[]::new); for(Employee employee: men){…