🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
October 20, 2025 - The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase. Case mapping is based on the Unicode Standard version specified by the Character class. The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings.
🌐
W3Schools
w3schools.com › java › java_strings.asp
Java Strings
A String in Java is actually an object, which means it contains methods that can perform certain operations on strings.
Discussions

What Every Java Developer should know about String
[String.split() is] particularly useful if you dealing with comma separated file (CSV) and wanted to have individual part in a String array. No. Fuck you to hell if you parse CSV this way. It will break, and it will all be your fault. CSV allows for commas to be inside the records as long as they're quoted (or escaped), so a line in a CSV file could look like this: "There is only one record on this line. Because it has commas inside quotes, it is one single, unbroken record" String.split() will parse that line wrong. More on reddit.com
🌐 r/java
43
49
January 7, 2014
What is the purpose of the expression "new String(...)" in Java? - Stack Overflow
While looking at online code samples, I have sometimes come across an assignment of a String constant to a String object via the use of the new operator. For example: String s; ... s = new String(" More on stackoverflow.com
🌐 stackoverflow.com
What is the difference between string[] and string
String is a single instance of a string. String[] is an array of strings. A collection. So when you split a string, you are saying "break this one string up into multiple strings, by splitting it on a specific substring". So, you start with one string, and end up with a collection of strings. More on reddit.com
🌐 r/learnprogramming
8
1
May 16, 2022
JEP 430: String Templates (Preview)
Personally I find it most interesting and innovative that this is apparently going to include validation, basically allowing for safely writing SQL statements in a String Template even with untrusted arguments. For example: ResultSet rs = DB."SELECT * FROM Person p WHERE p.last_name = \{name}"; Edit: I was made aware that Scala has a similar feature: https://docs.scala-lang.org/overviews/core/string-interpolation.html#advanced-usage More on reddit.com
🌐 r/java
86
89
August 13, 2022
🌐
Java Handbook
javahandbook.com › java-strings › what-is-a-string-in-java
What is a String in Java?
August 24, 2025 - A String is a sequence of characters used to represent textual data, such as letters, numbers, or symbols. Unlike other programming languages, Java does not treat strings as a primitive data type (like int or char).
🌐
OpenJDK
openjdk.org › jeps › 8344154
JEP draft: Convenience Methods for JSON Documents
2 days ago - A conversion method succeeds only if the JSON value is of the asserted JSON type and it can be converted to the desired Java type. string() asserts that the JsonValue is a JsonString and returns a Java String that represents the JSON string with all RFC 8259 JSON escape sequences translated ...
🌐
CodeGym
codegym.cc › java blog › strings in java › java strings
Java Strings
March 4, 2025 - In programming, strings are very commonly used. String in java is an object that represents a sequence of characters backed by a char array. String class is immutable in Java and implements Comparable, Serializable, and CharSequence interfaces.
🌐
JSON
json.org
JSON
JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › lang › String.html
String (Java SE 11 & JDK 11 )
January 20, 2026 - The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase. Case mapping is based on the Unicode Standard version specified by the Character class. The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings.
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › what-is-java-string-pool
What is Java String Pool? | DigitalOcean
August 3, 2022 - If there is already a string literal “Cat” in the pool, then only one string “str” will be created in the pool. If there is no string literal “Cat” in the pool, then it will be first created in the pool and then in the heap space, so a total of 2 string objects will be created. Read: Java String Interview Questions
🌐
Quarkus
quarkus.io › blog › k8s-style-CEL-with-quarkus-chicory
A Go CEL Policy Engine in Java, with Quarkus Chicory - Quarkus
2 weeks ago - //go:wasmexport evalPolicy func evalPolicy(policyPtr, policyLen, inputPtr, inputLen uint32) int32 { // Convert pointers to Go types policy := unsafe.String((*byte)(unsafe.Pointer(uintptr(policyPtr))), policyLen) inputJSON := unsafe.Slice((*byte)(unsafe.Pointer(uintptr(inputPtr))), inputLen) // Parse the JSON input var input map[string]any if err := json.Unmarshal(inputJSON, &input); err != nil { return -1 // JSON parse error } // Create CEL environment env, err := cel.NewEnv( cel.Declarations( decls.NewVar("object", decls.NewMapType(decls.String, decls.Dyn)), ), ) if err != nil { return -2 //
🌐
GeeksforGeeks
geeksforgeeks.org › java › string-arrays-in-java
String Arrays in Java - GeeksforGeeks
October 2, 2025 - A String Array in Java is an array that stores string values.
🌐
Medium
medium.com › @smita.s.kothari › all-about-strings-in-java-a-comprehensive-guide-with-examples-9c9a59724392
All About Strings in Java: A Comprehensive Guide with Examples | by Smita Kothari | Medium
April 7, 2025 - In Java, a String is an object that represents a sequence of characters. Unlike primitive data types, strings are handled as objects of the String class in Java.
🌐
Medium
medium.com › geekculture › a-deep-dive-into-java-string-e5f67ccbdba8
A deep dive into Java String. Do you really know Java strings? | by Tech & Math | Geek Culture | Medium
March 22, 2022 - To be able to understand all of those outcomes, we need to first dive into the working mechanism of the String class. In Java’s implementation of String class, we can see it contains final char[] value. It contains the final keyword, so we know the String class value can only be assigned once, making the value attribute immutable.
🌐
Quora
quora.com › What-is-string-in-Java-3
What is string in Java? - Quora
Answer (1 of 5): It is a data type that stores values in text format. It is assigned to a variable to tell the compiler that this variable will store data in text format. That variable is then called a string variable.
🌐
Programiz
programiz.com › java-programming › string
Java String (With Examples)
In Java, a string is a sequence of characters. For example, "hello" is a string containing a sequence of characters 'h', 'e', 'l', 'l', and 'o'. In this tutorial, we will learn about strings in Java with the help of examples.
🌐
Medium
medium.com › geekculture › all-about-string-in-java-51ba9e46181a
All About String in Java. Java Strings are objects that are… | by sajith dilshan | Geek Culture | Medium
February 8, 2023 - All About String in Java Java Strings are objects that are backed by a char array and are immutable. The class java.lang.String is used to create a string object. There are two ways to create a …
🌐
Baeldung
baeldung.com › home › java › java string › guide to java string pool
Guide to Java String Pool | Baeldung
August 20, 2025 - When we create a String variable and assign a value to it, the JVM searches the pool for a String of equal value. If found, the Java compiler will simply return a reference to its memory address, without allocating additional memory.
🌐
Reddit
reddit.com › r/java › what every java developer should know about string
r/java on Reddit: What Every Java Developer should know about String
January 7, 2014 - This can be dangerous if original string object is very large and substring is very small, because even a small fraction can hold reference of complete array and prevents it from being garbage collected even if there is no other reference for that particular String. This is no longer true. Substrings are now always fresh copies. ... Yeah, that's true for Java 7, but not for Java 6.
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java string class
Java String Class
September 1, 2008 - Strings, which are widely used in Java programming, are a sequence of characters.
Top answer
1 of 9
84

The one place where you may think you want new String(String) is to force a distinct copy of the internal character array, as in

small=new String(huge.substring(10,20))

However, this behavior is unfortunately undocumented and implementation dependent.

I have been burned by this when reading large files (some up to 20 MiB) into a String and carving it into lines after the fact. I ended up with all the strings for the lines referencing the char[] consisting of entire file. Unfortunately, that unintentionally kept a reference to the entire array for the few lines I held on to for a longer time than processing the file - I was forced to use new String() to work around it, since processing 20,000 files very quickly consumed huge amounts of RAM.

The only implementation agnostic way to do this is:

small=new String(huge.substring(10,20).toCharArray());

This unfortunately must copy the array twice, once for toCharArray() and once in the String constructor.

There needs to be a documented way to get a new String by copying the chars of an existing one; or the documentation of String(String) needs to be improved to make it more explicit (there is an implication there, but it's rather vague and open to interpretation).

Pitfall of Assuming what the Doc Doesn't State

In response to the comments, which keep coming in, observe what the Apache Harmony implementation of new String() was:

public String(String string) {
    value = string.value;
    offset = string.offset;
    count = string.count;
}

That's right, no copy of the underlying array there. And yet, it still conforms to the (Java 7) String documentation, in that it:

Initializes a newly created String object so that it represents the same sequence of characters as the argument; in other words, the newly created string is a copy of the argument string. Unless an explicit copy of original is needed, use of this constructor is unnecessary since Strings are immutable.

The salient piece being "copy of the argument string"; it does not say "copy of the argument string and the underlying character array supporting the string".

Be careful that you program to the documentation and not one implementation.

2 of 9
10

The only time I have found this useful is in declaring lock variables:

private final String lock = new String("Database lock");

....

synchronized(lock)
{
    // do something
}

In this case, debugging tools like Eclipse will show the string when listing what locks a thread currently holds or is waiting for. You have to use "new String", i.e. allocate a new String object, because otherwise a shared string literal could possibly be locked in some other unrelated code.