DEV Community

DominicScarcello22347
DominicScarcello22347

Posted on

CSA String Class

The String Class is used to print long lines of characters. They are constant meaning that their values can not be changed after they are created. Since strings cannot be changed, or are immutable, they can be shared. The string class can be used to do many things with its methods including examining individual characters of a sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase and lowercase. There are two was to create a string in java String literal: String s = "example"; and Using new keyword: String s = new String ("Example");. In the java language there is special support for the string concatenation operator (+), and for conversion of other objects to strings. It is implemented through the StringBuffer class. String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java.

Some examples of Constructors:
public String() = Allocates a new String containing no characters
public String(String value) = new string that contains the same sequence of characters as the string argument

Sources:
https://courses.cs.washington.edu/courses/cse341/98au/java/jdk1.2beta4/docs/api/java/lang/String.html
https://www.geeksforgeeks.org/string-class-in-java/
https://beginnersbook.com/2013/12/java-strings/

Top comments (0)