JAVA Tutorial (6 Part Series)
1 1. Hello World in JAVA
2 2. Variables, Datatypes, Operators in JAVA
… 2 more parts…
3 3. String in JAVA
4 4. Operators, Operands, Expression, Operator Precedence
5 5. If-then block in JAVA
6 6. Expressions, Statements, if-then-else , Methods, Method Overloading
A string is a sequences of characters. In the case of the char, char contains a single character only.
A String can contain a sequence of characters.
Exmaple:
String name = "Rittwick Bhabak"
3 Strings in Java are Immutable
String name = "Rittwick";
String name = name + "Bhabak";
Enter fullscreen mode Exit fullscreen mode
In the above code, name
doesn’t get appended the value “Bhabak” instead a new String is created which consists of the previous value of name
plus “Bhabak”.
The net result is same, name
has the right values, however, a new String
got created and the old one got discarded.
So, String is immutable in Java.
There are a class in Java called StringBuffer which can be changed.
原文链接:3. String in JAVA
暂无评论内容