Java - 字符串(String)

Java - 字符串(String)


There is no primitive type for strings in Java. But there is a class called String used to store and process strings. For example,

String s = "I fall in love with ZL";

字符串的连接(Concatenation of Strings)
We use + operator to concatenate two strings. For example,

String str = "Welcome to "+"Melbourne";
str: Welcome to Melbourne

String str2 = "The grade of Java is "+100;
str2: The grade of Java is 100

String name = "Shuaishuai";
String str3 = "Linlin loves "+name;
str3: Linlin loves Shuaishuai;

String str4 = "12400"+31;
str4: 1240031

方法(Methods)
There are some methods frequently used. Go to String class. Check it out.

int length()
boolean equals(Other_String)
boolean equalsIgnoreCase(Other_String)
String toLowerCase()
String toUpperCase()
String trim()
char charAt(Position)
String substring(Start)
String substring(Start, End)
int indexOf(A_String)
int indexOf(A_String, Start)
int lastIndexOf(A_String)
int compareTo(A_String)
int compareToIgnoreCase(A_String)

转义字符串(Escape Sequences)
A backslash \ preceding a character tells the compiler that the character has its usual meaning. For example,

String str = "she said, \"I love you\".";

String str2 = "The character \'x\' means mystery.";

String str3 = "The storage path is C:\\Java\\projectB\\src\\Hello.class";

String str4 = "first row\nsecond row\nthird row";

统一码(The Unicode Character Set)
Remember Java uses the Unicode Character Set.

最后再说两句(PS)
Note that String is a class not a primitive type.
Welcome questions always and forever.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值