package stream;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class StreamExample16 {
    public static void main(String[] args) {
        List<Transaction> transactions = Arrays.asList(
                new Transaction(1000L),
                new Transaction(2500L),
                new Transaction(1500L)
        );

        // 使用 Collectors.summingLong 计算总金额
        long totalAmount = transactions.stream()
                .collect(Collectors.summingLong(Transaction::getAmount));

        System.out.println("Total Amount: " + totalAmount);
    }

    @Getter
    static class Transaction {
        private final long amount;

        public Transaction(long l) {
            this.amount = l;
        }
    }
}


