Bir String’in Uzunluğu Nasıl Belirlenir? (Java)

string.length (): length () yöntemi, string nesneleri için geçerli olan son bir değişkendir. length () yöntemi, string’de sunulan karakter sayısını döndürür.

array.length: length, diziler için geçerli olan son bir değişkendir. Dizinin boyutunu elde edebiliriz.

public class LengthOfAWord {

    public static void main(String[] args) {
        String s = "Hello my Name is Apple";
        System.out.println("Length: " + s.length());
    }
}
Output:
Length: 22
public class LengthOfAWord {

    public static void main(String[] args) {

        String[] s = {"Hello", "my name", "is apple"};
        System.out.println("Length: " + s.length);
    }
}
Output:
Length : 3
public class LengthOfAWord {

    public static void main(String[] args) {

        String[] s = {"Hello", "my name", "is apple"};
        System.out.println("Length: " + s[0].length());
    }
}
Output:
Length : 5
public class LengthOfAWord {

    public static void main(String[] args) {

        String[] s = {"Hello", "my name", "is apple"};
        System.out.println("Length: " + s.length);

        System.out.println("Length: " + s[0].length());
        System.out.println("Length: " + s[1].length());
        System.out.println("Length: " + s[2].length());

    }
}

Output:
Length: 3
Length: 5
Length: 7
Length: 8