# How to convert a list of objects to a list of strings in Java

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Oct 29, 2022. Topics: Java.
Canonical URL: https://attacomsian.com/blog/java-convert-a-list-of-objects-to-list-of-strings

> Learn how to use the Streams API methods to convert a list of objects to a list of strings in Java.

To convert a list of objects to a list of strings in Java, you can use the Streams API `map()` method. Suppose we have the following `User.java` class that stores user information.

```java
public class User {
    private String name;
    private String profession;
    private int age;

    public User(String name, String profession, int age) {
        this.name = name;
        this.profession = profession;
        this.age = age;
    }

    // getters and setters, equals(), toString() .... (omitted for brevity)
}
```

The following example demonstrates how you can convert a list of `User` objects into a list of strings using Java 8 streams:

```java
// Create a list of users
List<User> users = List.of(
        new User("John Doe", "Engineer", 23),
        new User("Alex Mike", "Doctor", 43),
        new User("Jovan Lee", "Lawyer", 34)
);

// Convert list of users to list of strings
List<String> list = users.stream()
        .map(User::toString)
        .collect(Collectors.toList());

// Print list of strings
list.forEach(System.out::println);

// User{name='John Doe', profession='Engineer', age=23}
// User{name='Alex Mike', profession='Doctor', age=43}
// User{name='Jovan Lee', profession='Lawyer', age=34}
```

To convert a list of `User` objects to a list of `name` values, you can do the following:

```java
List<String> list = users.stream()
        .map(User::getName)
        .collect(Collectors.toList());

list.forEach(System.out::println);

// John Doe
// Alex Mike
// Jovan Lee
```
