字符字面表示字母(两种情况)、数字(0到9)、特殊字符(@
, ?
, &
等)和转义序列,如 , \b
等。而字符串字头则代表字符串类的对象。
public class LiteralsExample {
public static void main(String args[]){
char ch = 'H';
String str = "Hello";
System.out.println("Value of character: "+ch);
System.out.println("Value of string: "+str);
}
}
运行结果:
Value of character: H
Value of string: Hello