
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Convert String to List of Characters in Java
Let’s say the following is our string −
String str = "Website!";
Now, convert the above string to a list of characters −
List<Character>list = str.chars().mapToObj(n -> (char)n).collect(Collectors.toList());
Example
Following is the program to convert a string to a list of characters in Java −
import java.util.*; import java.util.stream.Collectors; public class Demo { public static void main(String[] args){ String str = "Website!"; System.out.println("String = "+str); List<Character>list = str.chars().mapToObj(n -> (char)n).collect(Collectors.toList()); System.out.println("List of Characters = "+list); } }
Output
String = Website! List of Characters = [W, e, b, s, i, t, e, !]
Advertisements