

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
String Formatting in Java using %
Followimg is the code to implement String formatting in Java using % −
Example
public class Demo { public static void main(String args[]){ String my_str = " sample."; String concat_Str = String.format("This is a" + "%s", my_str); String format_str_1 = String.format("The value is %.4f", 78.92367); System.out.println(concat_Str); System.out.println(format_str_1); } }
Output
This is a sample. The value is 78.9237
A class named Demo contains the main function. Here a string value is defined, which is used to format the string, by concatenating it to another variable. Similarly, a floating point number is also formatted using the ‘%’ operator. Both these values are printed on the console.
- Related Questions & Answers
- String Formatting in C# using %
- String Formatting in Python using %?
- String Formatting Operator in Python
- Formatting day of week using SimpleDateFormat in Java
- String Formatting with ToString in C#
- Date Formatting Using printf
- Date Formatting Using SimpleDateFormat
- Formatting Text Using CSS
- How to print a complete tuple in Python using string formatting?
- Locale-specific formatting in Java
- String Formatting in C# to add padding
- How does string formatting work in PowerShell?
- Change date formatting symbols in Java
- Formatting Minute in m format in Java
- Formatting day in d format in Java
Advertisements