Java convert string to char using charAt() method
package com.w3schools; public class StringToChar { public static void main(String args[]){ String str = "w3schools"; for(int i=0; i<str.length();i++){ //Retrieve char from string char ch = str.charAt(i); System.out.println("Character at "+i+" Position: "+ch); } } }
Output:
Character at 0 Position: w Character at 1 Position: 3 Character at 2 Position: s Character at 3 Position: c Character at 4 Position: h Character at 5 Position: o Character at 6 Position: o Character at 7 Position: l Character at 8 Position: s