Top community members
All Wiki Articles Create Wiki Article

Many years me and my friends we were volunteers on my university doing programming classes for young people.

I got main conclusion: Young people are awesome, especially students, because they always bring new and fresh ideas :)
* I loved to do it but my time is limited

  I decided to create something that will help millions of students

Now I am here

co-founder

Java - convert String to List<Character>

0 contributions
12 points

1. Using Java 8 stream

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

public class Example1 {

    public static void main(String[] args) {

        String text = "abc";

        List<Character> list = text.chars()
                .mapToObj(c -> (char) c)
                .collect(Collectors.toList());

        System.out.println(list); // [a, b, c]
    }
}

Output:

[a, b, c]

Note:
In Java there is more then 1 way to create stream of characters from String, take a look on this post:

Java 8 - convert char[] to Stream<Character>

2. Explicit iteration

import java.util.ArrayList;
import java.util.List;

public class Example2 {

    public static void main(String[] args) {

        String text = "abc";

        List<Character> list = new ArrayList<>();
        for (char c : text.toCharArray()) {
            list.add(c);
        }

        System.out.println(list); // [a, b, c]
    }
}

Output:

[a, b, c]

Merged questions

  1. Java - convert String to List of Characters
  2. How do I create List<Character> from String in java?
0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more