- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the Length of a String in Java?
You can get the length of a string using the length() method of the String class. The length is equal to the number of 16-bit Unicode characters in the string.
Example
import java.io.*; public class Test { public static void main(String args[]) { String Str1 = new String("Welcome to Tutorialspoint.com"); String Str2 = new String("Tutorials" ); System.out.print("String Length :" ); System.out.println(Str1.length()); System.out.print("String Length :" ); System.out.println(Str2.length()); } }
Output
String Length :29 String Length :9
- Related Articles
- How to get the length of a string in Python?
- How to get the length of a string in JavaScript?
- How to get the length of a string in bytes in JavaScript?
- How to get the length of longest string in a PHP array
- Get the length of a StringBuffer Object in Java
- How do I get the average string length in MySQL?
- How To Get the Arc Length from Given Angle in Java?
- How to get the length of a Number in JavaScript?
- How to find the length of a string in TypeScript?
- How to get the string representation of numbers using toString() in Java?
- How do I get length of list of lists in Java?
- How to get the size of a string in Python?
- PHP – Get the string length using mb_strlen()
- How to get a substring of a particular string in Java. Explain with an example.
- How to get length of a list of lists in Python?

Advertisements