You can always use String.format(....). i.e.,

String string = String.format("A String %s %2d", aStringVar, anIntVar);

I'm not sure if that is attractive enough for you, but it can be quite handy. The syntax is the same as for printf and java.util.Formatter. I've used it much especially if I want to show tabular numeric data.

Answer from Hovercraft Full Of Eels on Stack Overflow
🌐
W3Schools
w3schools.com › java › java_variables.asp
Java Variables
In Java, there are different types of variables, for example: String - stores text, such as "Hello".
Discussions

Difference between creating a string object vs a string variable in java ?
A string variable either stores the special value null, or a reference to a string object. Multiple string variables can refer to the same string object. String literals like "hello" end up in the constant pool. All occurrences of "hello" evaluate to the same string reference. More on reddit.com
🌐 r/learnprogramming
2
1
December 26, 2022
The String variable in Java
Geroge Harris is having issues with: Why do String declarations need a capital S for 'String' while 'int' , 'char', 'boolean' types are all ok with lower case? This is 90% j... More on teamtreehouse.com
🌐 teamtreehouse.com
3
November 16, 2014
String[] variable vs String variable[]??? - Processing Forum
Java doesn't use Strings that way. Ok, it actually does if you insist: More on forum.processing.org
🌐 forum.processing.org
October 20, 2012
I do not understand String and Variables. Are they [String variables] or two different things. Need help to understand.
printf is a command that formats ... string with whatever String we pass to it in the second argument. It's worth nothing that this line of code from your examples: ... Is incorrect. variable is not a keyword that has any meaning on its own in Java, when you define a variable ... More on teamtreehouse.com
🌐 teamtreehouse.com
3
October 17, 2016
🌐
Syntaxdb
syntaxdb.com › ref › java › string-var
String Variables in Java - SyntaxDB - Java Syntax Reference
A string variable must be initialized with either a value (which will be permanent) or null (for later initialization). String name = "Anthony"; System.out.println("Hello, your name is " + name); Related · Variable Declaration Documentation · String Class - Java Docs ·
🌐
GeeksforGeeks
geeksforgeeks.org › java › variables-in-java
Java Variables - GeeksforGeeks
In Java, variables are containers used to store data in memory. Variables define how data is stored, accessed, and manipulated. ... Data Type: Defines the kind of data stored (e.g., int, String, float).
Published   November 11, 2025
🌐
Baeldung
baeldung.com › home › java › java string › string interpolation in java
String Interpolation in Java | Baeldung
July 23, 2025 - In this tutorial, we’ll discuss the topic of String interpolation in Java. We’ll look at a few different examples, and then go through some of the details. String interpolation is a straightforward and precise way to inject variable values into a string. It allows users to embed variable references directly in processed string literals.
Find elsewhere
🌐
Edureka
edureka.co › blog › java-string
Java Strings - How to Declare String in Java With Examples
February 13, 2025 - ( Corrections are in bold letters) 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 object in the heap.
🌐
W3Schools
w3schools.com › java › java_strings.asp
Java Strings
Java Examples Java Videos Java ... ... Strings are used for storing text. A String variable contains a collection of characters surrounded by double quotes (""):...
🌐
Oracle
docs.oracle.com › javase › tutorial › java › data › strings.html
Strings (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
Whenever it encounters a string literal in your code, the compiler creates a String object with its value—in this case, Hello world!. As with any other object, you can create String objects by using the new keyword and a constructor. The String class has thirteen constructors that allow you to provide the initial value of the string using different sources, such as an array of characters:
🌐
Processing Forum
forum.processing.org › topic › string-variable-vs-string-variable
String[] variable vs String variable[]??? - Processing Forum
October 20, 2012 - Same thing with i++ and ++i to increment and de-increment --i and i--...they both seem to do the same thing. String[] target1 = new String[6]; //target1 is an array of 6 strings? String target2[] = new String[6]; //target2 is a string of size 6? ... Thank you for the comments. McK ... I think you're confusing Java's String objects with C-strings, which are arrays (of chars).
🌐
Arch Linux Forums
bbs.archlinux.org › viewtopic.php
Java: String -> variable name? / Programming & Scripting / Arch Linux Forums
July 7, 2010 - Better solution: just keep the variables in a hash to begin with. It's what they're there for. class Foo { java.util.Map<String, Object> attributes; Foo() { this.attributes = new java.util.HashMap<String,Object>(); } Object setAttribute(String key, Object value) { return attributes.put(key, value); } Object getAttribute(String key) { return attributes.get(key); } public static void main(String[] args) { Foo obj = new Foo(); obj.setAttribute("bar", 42); System.out.printf("bar is %d\n", obj.getAttribute("bar")); } }
🌐
Team Treehouse
teamtreehouse.com › community › i-do-not-understand-string-and-variables-are-they-string-variables-or-two-different-things-need-help-to-understand
I do not understand String and Variables. Are they [String variables] or two different things. Need help to understand. (Example) | Treehouse Community
October 17, 2016 - printf is a command that formats a string based on placeholders placed in it, in this case it will replace the "%s" found in the string with whatever String we pass to it in the second argument. It's worth nothing that this line of code from your examples: ... Is incorrect. variable is not a keyword that has any meaning on its own in Java, when you define a variable you do so by first telling Java what type of data you will be storing in the variable and then the name of the variable.
🌐
Medium
medium.com › omarelgabrys-blog › more-about-strings-in-java-fb2480af8a19
More About Strings In Java. Strings in Java are a sequence of… | by Omar Elgabry | OmarElgabry's Blog | Medium
February 17, 2017 - Since they are immutable, the string object will reference another place in the memory and the previous object will be available for the garage collector(if it’s not assigned to another string variable). String str1 = "Java is fun!"; String str2 = str1;str2 = "Strings are immutable"; // str2 is no longer points to "Java is fun!"System.out.println(str1); // Java is fun!
🌐
Reddit
reddit.com › r/javahelp › how are we able to reassign the value of string in java if strings are immutable?
r/javahelp on Reddit: How are we able to reassign the value of String in java if Strings are immutable?
August 23, 2022 -

String s= "Hello";

s="Hi";

It prints Hi , How that is possible ,I am confused here . Strings are immutable means we cannot change alter the value stored in it . if we change the value then , a new string object will be created with a new memory location

String b=s.replace("Hello","Hey"); This method replaces the string value and stores in new memory location by creating new string object called b .How reassigning of strings are possible ? if Strings are immutable

🌐
GeeksforGeeks
geeksforgeeks.org › java › strings-in-java
Java Strings - GeeksforGeeks
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.
Published   January 13, 2026
🌐
Home and Learn
homeandlearn.co.uk › java › string_variables.html
java for complete beginners - string variables
Assign a value to your new string variable by typing an equals sign. After the equals sign the text you want to store goes between two sets of double quotes: ... We're saying print out whatever is in the variable called first_name. We then have a plus symbol, followed by a space. The space is enclosed in double quotes. This is so that Java will recognise that we want to print out a space character.
🌐
Baeldung
baeldung.com › home › java › java string › string initialization in java
String Initialization in Java | Baeldung
January 8, 2024 - First of all, we should remember how Strings are created in Java. ... And, it’s also important that we understand how Strings are managed in a specialized pool. First, let’s just declare a String, without assigning a value explicitly. We can either do this locally or as a member variable:
🌐
Coders Campus
coderscampus.com › home › strings in java – what’s so special about a string?
Strings in Java - What's so special about a String?
April 9, 2021 - You see, all variables in Java will be stored in memory on your computer. The variables will be assigned a location that is identified by an address. Think of the address in memory like your own home address. If you create a new String variable, it will be assigned an address that is currently empty.
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › datatypes.html
Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
Unicode escape sequences may be ... not just in char or String literals. The Java programming language also supports a few special escape sequences for char and String literals: \b (backspace), \t (tab), \n (line feed), \f (form feed), \r (carriage return), \" (double quote), \' (single quote), and \\ (backslash). There's also a special null literal that can be used as a value for any reference type. null may be assigned to any variable, except variables ...