我有一个Object列表。我想打印除firstName为“Avijit”的一个对象以外的所有对象。我怎么能用流做?

时间:2018-04-24 05:32:47

标签: stream

这里是代码

import java.util.List;


public class StreamDemo {

    public static void main(String[] args) {

        List<User> name = new ArrayList<>();
        name.add(new User(1,"Avijit","Barua","aavi1234"));
        name.add(new User(2,"Mezanul","Haque","mezan1234"));
        name.add(new User(3,"Subrata","Nath","subrata1234"));
        name.add(new User(4,"Raman","Karmakar","raman1234"));
        name.add(new User(5,"Mowdud","Ahmed","mowdud1234"));

    }
}

1 个答案:

答案 0 :(得分:1)

似乎我得到了答案。

name.stream()
    .filter(p -> p.getFirstName()!="Avijit")
    .forEach(p -> System.out.println(p));