Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

public class Main {
    public static void main(String args[]) {
        List<Person> people = Arrays.asList(new Person("B", 25, "Main Street"), new Person("A", 27, "Off Street"));
        List<String> listNames = people.stream().map(u -> u.getName()).collect(Collectors.toList());
        System.out.println(listNames);
    }
}

class Person {
    private String name;
    private int age;
    private String location;

    public Person(String name, int age, String location) {
        this.name = name;
        this.age = age;
        this.location = location;
    }

    public String getName() {
        return this.name;
    }
}