+ 2
When i parse character it says an error but when its an Integer its just fine
public class ProgramSample { public static void main(String[] args) { String flag = "f"; char a = Character.parseCharacter(flag); System.out.println(a); } }
3 Answers
+ 4
The method:
public static char parseCharacter(String)
doesn't exist in the Character class.
What are you trying to do?
If you're trying to convert a character in a String to a char use:
public class ProgramSample
{
public static void main(String[] args) {
String flag = "f";
char a = flag.charAt(0);
System.out.println(a);
}
}
+ 4
First, your code looks more like you are trying to convert a String into a char. parseChararacter(String) is not a method in Java. If you think about it it wouldn't make sense to parse an entire String for 1 char, when a String is potentially made up of multiple characters. If you're wanting to get a character from a String then you need to extract that 1 char from the String first, which the String.charAt(index) method will accomplish. Converting a char to a String can be as simple as calling a toString() method or using the String.valueOf(char) or using String concatenation.
+ 1
@ChoacticDawg thanks for your answer so basically your saying that I can't parse a char using the term parseChar to convert it to a string?