Table of Contents [hide]
String’s length method is used to calculate length of String. It returns number of character in the String.
When you run above program, you will get below output:
Method Signature:
1 2 3 |
public int length() |
String length Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
package org.arpit.java2blog; public class StringLengthExample { /* * @Author: Arpit Mandliya */ public static void main(String[] args) { // 1st String str1 = "Hello world from java2blog.com"; // 2nd String str2 = "Core java programming tutorials"; // 3rd String str3 = "JAVA PROGRAMMING TUTORIALS"; //4th String str4=""; System.out.println("str1's length : "+str1.length()); System.out.println("str2's length : "+str2.length()); System.out.println("str3's length : "+str3.length()); System.out.println("str4's length : "+str4.length()); } } |
1 2 3 4 5 6 |
str1's length : 30 str2's length : 31 str3's length : 26 str4's length : 0 |
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.