- 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
Java string length without using length() method.
To calculate the length of the string convert the string to a character array and count the number of elements in the array.
Example
public class StringLength { public static void main(String args[]) throws Exception { String str = "sampleString"; int i = 0; for(char c: str.toCharArray()) { i++; } System.out.println("Length of the given string ::"+i); } }
Output
Length of the given string ::12
- Related Articles
- Java String length() method example.
- StringJoiner length() method in Java 8
- Python Program to Calculate the Length of a String Without Using a Library Function
- Program to find length of a list without using built-in length() function in Python
- Replace Character in a String in Java without using replace() method
- PHP – Get the string length using mb_strlen()
- Write program to reverse a String without using reverse() method in Java?
- How MySQL LENGTH() function measures the string length?
- How to find length of a string without string.h and loop in C?
- C++ program for length of a string using recursion
- How to find the length of the longest substring from the given string without repeating the characters using C#?
- How to get the Length of a String in Java?
- How to calculate the length of the string using C#?
- Get the last item from node list without using length property in JavaScript?
- Python Program to Find the Length of the Linked List without using Recursion

Advertisements