Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading Characters from a Word ? Java

I am trying to get the characters or the letters from a word.

For example:

input = "apple"
output = "a", "p", "p", "l", "e"

However, I am using the BufferedReader class. Is there any way to read characters using BufferedReader?

Thank you

like image 640
COLD ICE Avatar asked Apr 15 '13 08:04

COLD ICE


2 Answers

String input = "apple";
char[] arr = input.toCharArray();
System.out.println(Arrays.toString(arr));

Output:

[a, p, p, l, e]
like image 55
Achintya Jha Avatar answered Oct 21 '22 10:10

Achintya Jha


The read() method of BufferedReader gives you a single character.

Have a look at this.

like image 26
Sachin Kainth Avatar answered Oct 21 '22 10:10

Sachin Kainth