Java Convert String to charWe can convert String to char in java using charAt() method of String class. The charAt() method returns a single character only. To get all characters, you can use loop. SignatureThe charAt() method returns a single character of specified index. The signature of charAt() method is given below: Java String to char Example: charAt() methodLet's see the simple code to convert String to char in java using charAt() method. Let's see the simple example of converting String to char in java. Test it NowOutput: 1st character is: h Let's see another example to convert all characters of a string into character. Test it NowOutput: char at 0 index is: h char at 1 index is: e char at 2 index is: l char at 3 index is: l char at 4 index is: o Java String to char Example: toCharArray() methodLet's see the simple code to convert String to char in java using toCharArray() method. The toCharArray() method of String class converts this string into character array. Test it NowOutput: char at 0 index is: h char at 1 index is: e char at 2 index is: l char at 3 index is: l char at 4 index is: o Next TopicJava char to String |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India