🌐
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. For example, you can find the length of a string with the length() method:
🌐
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.
Discussions

How do I split a string in Java? - Stack Overflow
As the pattern is fixed in this ... in the example). The regular expression is: ... The parentheses denote the capturing groups; the string that matched that part of the regexp can be accessed by the Match.group() method, as shown. The \d matches and single decimal digit, and the + means "match one or more of the previous expression). The - has no special meaning, so just matches that character in the input. Note that you need to double-escape the backslashes when writing this as a Java ... More on stackoverflow.com
🌐 stackoverflow.com
How to create and initialise in Java an array of String arrays in one line? - Stack Overflow
please do check these too Docs ... with java docs , I had to add this as a comment but I couldn't, I want to extend with more resources mentioned above , Thanks ... We can also achieve it by initialising and assigning to a single dimensional array of type Object. Something like below. String[] filledArr ... More on stackoverflow.com
🌐 stackoverflow.com
Java Strings: "String s = new String("silly");" - Stack Overflow
Strings are special in Java - they're immutable, and string constants are automatically turned into String objects. There's no way for your SomeStringClass cis = "value" example to apply to any other class. More on stackoverflow.com
🌐 stackoverflow.com
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 20, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › java › strings-in-java
Java Strings - GeeksforGeeks
Here, Sachin is not changed but a new object is created with “Sachin Tendulkar”. That is why a string is known as immutable. As we can see in the given figure that two objects are created but s reference variable still refers to "Sachin" and not to "Sachin Tendulkar". But if we explicitly assign it to the reference variable, it will refer to the "Sachin Tendulkar" object. Example: Java program to assign the reference explicitly in String using String.concat() method.
Published   January 13, 2026
🌐
TheServerSide
theserverside.com › definition › Java-string
What Is a Java String?
August 26, 2022 - Below is one simple syntax for creating a Java string. ... In this example, "Hello world!" is a string literal, which is a series of characters encased in quotation marks.
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › java-strings
Java – String Class and Methods with examples
The problem with this approach: As I stated in the beginning that String is an object in Java. However we have not created any string object using new keyword in the above statements. The compiler does this internally and looks for the string in the memory (this memory is often referred as string constant pool). If the string is not found, it creates an object with the string value, which is “Welcome” in this example and assign a reference to this string.
🌐
Tutorialspoint
tutorialspoint.com › home › java › java strings
Java Strings
September 1, 2008 - Explore Java Strings, including methods and examples for efficient text manipulation in Java programming.
Find elsewhere
🌐
Edureka
edureka.co › blog › java-string
Java Strings - How to Declare String in Java With Examples
February 13, 2025 - By new keyword : Java String is created by using a keyword “new”. For example: String s=new String(“Welcome”); It creates two objects (in String pool and in heap) and one reference variable where the variable ‘s’ will refer to the ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
October 20, 2025 - The string "boo:and:foo", for example, yields the following results with these expressions: ... the array of strings computed by splitting this string around matches of the given regular expression ... Returns a new String composed of copies of the CharSequence elements joined together with a copy of the specified delimiter. ... String message = String.join("-", "Java", "is", "cool"); // message returned is: "Java-is-cool" Note that if an element is null, then "null" is added.
🌐
W3Schools
w3schools.com › java › java_ref_string.asp
Java String Reference
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... The String class has a set of built-in methods that you can use on strings.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-string-programs
Java String Programs - GeeksforGeeks
October 7, 2025 - Strings are widely used for storing and processing textual data in programs. Here is a complete list of Java String practice programs divided into basic and advanced categories:
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-string
Java String | DigitalOcean
August 3, 2022 - Let’s have a look at some of the popular String class methods with an example program. Java String split() method is used to split the string using given expression.
Top answer
1 of 16
3415

Use the appropriately named method String#split().

String string = "004-034556";
String[] parts = string.split("-");
String part1 = parts[0]; // 004
String part2 = parts[1]; // 034556

Note that split's argument is assumed to be a regular expression, so remember to escape special characters if necessary.

there are 12 characters with special meanings: the backslash \, the caret ^, the dollar sign $, the period or dot ., the vertical bar or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening parenthesis (, the closing parenthesis ), and the opening square bracket [, the opening curly brace {, These special characters are often called "metacharacters".

For instance, to split on a period/dot . (which means "any character" in regex), use either backslash \ to escape the individual special character like so split("\\."), or use character class [] to represent literal character(s) like so split("[.]"), or use Pattern#quote() to escape the entire string like so split(Pattern.quote(".")).

String[] parts = string.split(Pattern.quote(".")); // Split on the exact string.

To test beforehand if the string contains certain character(s), just use String#contains().

if (string.contains("-")) {
    // Split it.
} else {
    throw new IllegalArgumentException("String " + string + " does not contain -");
}

Note, this does not take a regular expression. For that, use String#matches() instead.

If you'd like to retain the split character in the resulting parts, then make use of positive lookaround. In case you want to have the split character to end up in left hand side, use positive lookbehind by prefixing ?<= group on the pattern.

String string = "004-034556";
String[] parts = string.split("(?<=-)");
String part1 = parts[0]; // 004-
String part2 = parts[1]; // 034556

In case you want to have the split character to end up in right hand side, use positive lookahead by prefixing ?= group on the pattern.

String string = "004-034556";
String[] parts = string.split("(?=-)");
String part1 = parts[0]; // 004
String part2 = parts[1]; // -034556

If you'd like to limit the number of resulting parts, then you can supply the desired number as 2nd argument of split() method.

String string = "004-034556-42";
String[] parts = string.split("-", 2);
String part1 = parts[0]; // 004
String part2 = parts[1]; // 034556-42
2 of 16
91

An alternative to processing the string directly would be to use a regular expression with capturing groups. This has the advantage that it makes it straightforward to imply more sophisticated constraints on the input. For example, the following splits the string into two parts, and ensures that both consist only of digits:

import java.util.regex.Pattern;
import java.util.regex.Matcher;

class SplitExample
{
    private static Pattern twopart = Pattern.compile("(\\d+)-(\\d+)");

    public static void checkString(String s)
    {
        Matcher m = twopart.matcher(s);
        if (m.matches()) {
            System.out.println(s + " matches; first part is " + m.group(1) +
                               ", second part is " + m.group(2) + ".");
        } else {
            System.out.println(s + " does not match.");
        }
    }

    public static void main(String[] args) {
        checkString("123-4567");
        checkString("foo-bar");
        checkString("123-");
        checkString("-4567");
        checkString("123-4567-890");
    }
}

As the pattern is fixed in this instance, it can be compiled in advance and stored as a static member (initialised at class load time in the example). The regular expression is:

(\d+)-(\d+)

The parentheses denote the capturing groups; the string that matched that part of the regexp can be accessed by the Match.group() method, as shown. The \d matches and single decimal digit, and the + means "match one or more of the previous expression). The - has no special meaning, so just matches that character in the input. Note that you need to double-escape the backslashes when writing this as a Java string. Some other examples:

([A-Z]+)-([A-Z]+)          // Each part consists of only capital letters 
([^-]+)-([^-]+)            // Each part consists of characters other than -
([A-Z]{2})-(\d+)           // The first part is exactly two capital letters,
                           // the second consists of digits
🌐
Medium
medium.com › @AlexanderObregon › a-beginners-guide-to-java-strings-3485cba0b517
Java Strings Guide For Beginners | Medium
February 23, 2024 - At the heart of Java’s text manipulation capabilities are “strings”. The goal of this beginner-friendly guide is to explain Java strings, providing you with a solid understanding of what strings are, how they function within the Java ecosystem, and practical examples to illustrate their use.
🌐
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. These concepts are followed in strongly typed languages (where variables stron...
🌐
Geekster
geekster.in › home › java string
Java String (with Example)
April 16, 2024 - When we concatenate a string like ” to all” with str, a new string value is created. str then points to this newly created value, while the original value remains unchanged. This behavior demonstrates the immutability of strings in Java. String is a fundamental class used for representing and manipulating textual data in Java programming.
🌐
Simplilearn
simplilearn.com › home › resources › software development › java tutorial for beginners › what are java strings and how to implement them?
What are Java Strings and How To Implement Them
July 23, 2024 - What are Java strings and how do you create them? Learn all about Java strings, the methods based on Java strings, sub strings, and more with example programs.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Crio
crio.do › blog › string-methods-in-java
10 Important String Methods In Java You Must Know
October 20, 2022 - 2. Using new: Using the keyword "new," a Java String is generated. Example: String greetString = new String(“Welcome”)