1

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.

Zaid
  • 21
  • 3
  • 2
    use String.toCharArray() and then print each element of array in separate line. – Sagar Gautam Apr 27 '17 at 13:06
  • Possible duplicate of [How to split a string in Java](http://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java) – pringi Apr 27 '17 at 13:26

1 Answers1

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
  • 1
    It 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