In this tutorial we are going to see how to get the length of any input string without using the length() function in Java.
Here is the code goes:
import java.io.*; import java.util.Scanner; public class lengthofstring { public static void main(String args[]) { Scanner sc = new Scanner(System.in); String mystring; mystring = sc.next(); int count = 0; for(char c : mystring.toCharArray()) { count++; } System.out.println("length is: " + count); } }
I hope this would help you for Interviews!
Sir without any builtin method
How to find string length not using any method find length of string.