Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

Java String length Method

by suresh

The Java String length Method is to find and return the length of the User specified string. The length is equal to the number of Unicode units in a string.

In this article, we will show how to find the length of a String using the Java string length method with an example. The basic syntax of the String length in Java Programming language is as shown below.

public int length() // It will return the integer Value as Output

//In order to use in program
String_Object.length()
  • String_Object: Please specify the valid String Object to find its length.

Java String length example

The String length method returns the length of the user-specified string. In this program, we are going to declare a few string objects and then find the length of those strings using this String function.

//How to find Length using Java String.length method
package StringFunctions;

public class StringLength {
	public static void main(String[] args) {
		String str = "Hello";
		int str1 = str.length();
		String str2 = "Tutorial GateWay";
		String str3 = "Free Java Tutorial at Tutorial GateWay";
		String str4 = "Java Programming Language";
		
		System.out.println("The Length of a String Str = " + str1);
		System.out.println("The Length of a String Str2 = " + str2.length());
		System.out.println("The Length of a String Str3 = " + str3.length());
		System.out.println("The Length of a String Str4 = " + str4.length());
	}
}

OUTPUT

Java String length Method 1

ANALYSIS

In this string length example, First, we declared the String variable and assigned a value using the following statement

String str = "Hello";

The following String function statement will find the length of the above-specified string. Here we are assigning the output to integer values because string length in java returns an integer value.

int str1 = str.length();

Next, we declared three more strings using the following Java statements

String str2 = "Tutorial GateWay";
String str3 = "Free Java Tutorial at Tutorial GateWay";
String str4 = "Java Programming Language";

The following System.out.println statements will call the public int length() method to find the string length and then print the output

System.out.println("The Length of a String Str2 = " + str2.length());
System.out.println("The Length of a String Str3 = " + str3.length());
System.out.println("The Length of a String Str4 = " + str4.length());

Placed Under: Java

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy