Sobes.tech
Junior — Senior

Stream API: filtering and transforming elements

livecode

Task condition

Given a collection List<A>. The task is to obtain List<B> by leaving only those A objects for which the calculated value y = 3 * x / 2 is an even number. Transformation of elements: a new object B(y) is created, where y is calculated as 3 * a.x / 2. Implement the task using the Stream API.

public class A { public int x; }

public class B {
    public int y;
    public B(int y) { this.y = y; }
}

List<A> listA = List.of(...);