Strings
Strings in Java are objects that represent a sequence of char values. A String can be created in two ways:
Using a literal
Using
new
keyword
TEXT/X-JAVA
1String str = "Hello World"; //using literal
2
3String website = new String("AlgoDaily"); //using new keyword
Note that the java.lang.String class implements Serializable, Comparable, and CharSequence interfaces. Since the String object is immutable(unable to be changed) in nature Java provides 2 utility classes:
StringBuilder, which is a mutable class that is not thread-safe but is faster and used in single-threaded
StringBuffer, which is a mutable class that is thread-safe and synchronized.
Below are some of the most useful String methods: