- length variable is used to calculate size of array.
- length() method is use to calculate size of string. Returns number of chars present in String.
1 2 3 4 5 6 7 8 9 10 11 |
import java.util.*; public class Main { public static void main(String[] args) { String[] str1={"welcome","to","webencyclop"}; String str2="webencyclop"; System.out.println("Length of array is: " + str1.length); System.out.println("Length of string is: " + str2.length()); } } |
Output:
1 2 |
Length of array is: 3 Length of string is: 11 |