Java

来源:互联网 发布:网络态势感知 dfi 编辑:程序博客网 时间:2024/06/15 12:18

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 MelbourneString str2 = "The grade of Java is "+100;str2: The grade of Java is 100String 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.