Relevant code:
Code: Select all
slist.stream().forEach(Student::debug);
public void debug(){
//sth
}
Moderators: Site Manager, fjwalraven
Code: Select all
slist.stream().forEach(Student::debug);
public void debug(){
//sth
}
Code: Select all
slist.stream().forEach(s -> s.debug());
Code: Select all
static class Student {
private String name;
private int marks;
public Student(String string, int i) {
this.name = string;
this.marks = i;
}
public void addMarks(int m) {
this.marks += m;
}
public void debug() {
System.out.println(name + ":" + marks);
}
public static void main(String[] args) {
List<Student> slist = Arrays.asList(new Student("S1", 40), new Student("S2", 35), new Student("S3", 30));
Consumer<Student> increaseMarks = s -> s.addMarks(10);
slist.forEach(increaseMarks);
slist.stream().forEach(Student::debug);
}
}
Code: Select all
static class Names {
private List<String> list;
public List<String> getList() {
return list;
}
public void setList(List<String> list) {
this.list = list;
}
public void printNames() {
System.out.println(getList());
}
public static void main(String[] args) {
List<String> list = Arrays.asList("Bob Hope","Bob Dole", "Bob Brown");
Names n = new Names();
n.setList(list.stream().collect(Collectors.toList()));
n.getList().forEach(Names::printNames);
}
}
Thank you very much for the warningadmin wrote:The statement has been updated to make it clear.
But please be aware that the real exam questions also may have similar statements.
thank you for your feedback.
Paul.
Users browsing this forum: No registered users and 26 guests