Java中的字符文字和字符串文字有什么区别?
字符文字代表字母(两种情况),数字(0到9),特殊字符(@、?等)和转义序列,例如\n,\b等。
而String文字表示String类的对象。
示例
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
热门推荐
10 毛笔哥哥结婚祝福语简短
11 向国庆送祝福语简短
12 建队节祝福语简短
13 朋友喜得外孙简短祝福语
14 小店营业的祝福语简短
15 餐饮生日祝福语简短独特
16 鲜花英语祝福语卡片简短
17 男朋友暴富祝福语简短
18 婶婶拜年祝福语大全简短