reference:http://examples.javacodegeeks.com/core-java/lang/string/java-string-class-example/
1. Introduction
In this example we are going to discuss about the basic characteristics of?.?String ?is probably one of the most used types in Java programs. That’s why Java provides a number of API methods that make?String ?manipulation easy and efficient,straight out of the box.?Strings ?are so important that even in the latest Java releases (including 7 and 8),several changes have been made to its class methods and its internal representation,improving it even further in terms of performance and security.??
2. String Class basic methods
A?String ?is simply a sequence of characters. As a matter of fact,a?String ?Object is backed by a?char ?array. Consequently,it is not null terminated,like in C/C++.
Here is how you can create a?String
1
</tr></table>
"Hello World" ?is called a?String ?literal. In a Java program,everything between two double quotes is a?String ?literal. Literals are implemented as instances of String class. As you can see,you can conveniently initialize a?String ?Object like a primitive type,e.g?int i = 0; .
There is no need to do:
1?
</tr></table>
There is a difference between these two initialization methods,although the result is the same : A?String ?with value “Hello World”. But more on that in just a bit.
For now,here is a simple?main ?with the most important?String ?API methods:
StringClassExample.java
|