There are following way to convert string with integer to characters in java.
- Here we iterate the given string from for loop and convert this string to char from str.charAt() method through index value.
- Inside if condition Character.isDigit() method is used to check whether the specified character is a digit or not. if it is digit then convert this digit to character.
- Finally, printing all the character on the console.
public class ConvertStringToChar {
public static void main(String[] args) {
String str = "98a7e3d";
char value = 0;
System.out.println("string with integer to characters :- ");
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if (Character.isDigit(ch)) {
int num = ch;
value = (char) (num + '0');
} else {
value = ch;
}
System.out.println(value);
}
}
}
Output:-
string with integer to characters :-
i
h
a
g
e
c
d