Вот код с пояснениями в комментариях.
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
//Note - Object.toString() was defined for AAA & BBB classes. Their member variables are public just to reduce code.
public class Test {
public static void main(String [] args){
//Generate some test data.
List<AAA> testData = Stream
.of(1,2,3,4,5)
.map(i -> new AAA(i+"", (i%3)+"", i*3+"", i*4+""))
.collect(Collectors.toList());//% is modulo operator.
System.out.println("Test data:\n");
testData.forEach(System.out::println);
List<BBB> processedData = testData
.stream()
//If a.A1 = a.A2, then allow it.
.filter(a -> a.A1.equals(a.A2))
//Take an AAA and convert it into a BBB.
.map(a -> new BBB(a.A3, a.A4))
//Collect all the BBBs and put them in a list.
.collect(Collectors.toList());
System.out.println("Processed data:\n");
processedData.forEach(System.out::println);
}
}
Вывод:
Test data:
AAA{A1='1', A2='1', A3='3', A4='4'}
AAA{A1='2', A2='2', A3='6', A4='8'}
AAA{A1='3', A2='0', A3='9', A4='12'}
AAA{A1='4', A2='1', A3='12', A4='16'}
AAA{A1='5', A2='2', A3='15', A4='20'}
Processed data:
BBB{A3='3', A4='4'}
BBB{A3='6', A4='8'}