Easy learning with example program codes

String to char in java

Java convert string to char using charAt() method

package com.codesjava;
public class StringToChar {
  public static void main(String args[]){
      String str = "codesjava";
      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);


Character at 0 Position: c
Character at 1 Position: o
Character at 2 Position: d
Character at 3 Position: e
Character at 4 Position: s
Character at 5 Position: j
Character at 6 Position: a
Character at 7 Position: v
Character at 8 Position: a

Download this example.

Please follow and like us:
Posted in Java   

Copyright © 2020 CodesJava Protection Status