Sobes.tech
Junior — Senior

Conversion of a list of objects with conditional selection

livecode

Task condition

There is a collection of instances of class A. It is required to form a new collection of objects of class B, where the value of field B.y is calculated by the formula 3 * A.x / 2. Only those elements for which the resulting B.y is an even number are included in the resulting collection.

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

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