I want such an output such that when the input is a string "HARSHA", then it must be split into the constituent alphabets and they should get printed on separate lines.
Asked
Active
Viewed 61 times
1 Answers
1
You can use the split() method in the class java.lang.String
String word = "ahmet enes";
String[] alphabets = word.split("");
for(String alphabet : alphabets)
{
System.out.println(alphabet);
}
Thanks to @Pshemo to remind me it may not work on previous versions

Ahmet Enes
- 102
- 7
-
1It is worth mentioning that this will work only since Java 8. In Java 7 and earlier we would get array starting with empty string like `"abc".split("")->["","a","b","c"]`. – Pshemo Apr 27 '17 at 13:08