how to get length of string in java android code example

Example 1: length of string in java

str.length();

Example 2: string length in java

String data = "Hello, World!";
int nameLength = data.length();

Example 3: java length of string

string.length()

Example 4: string length in android studio

text = et.getText().toString();
if (text == null || text.length() < 3 || text.length > 8) {
    tv.setText("Invalid length, should be from 3 to 8 characters. Please check your code");
} else {
    a = text.substring(0,1);
    b = text.substring(1,2);

    c = text.substring(3,4);
    if (text.length() > 3) {
      d = text.substring(4);
    } else {
         d = null;
    }
}

Tags:

Cpp Example