java manipulate alphabet list code example

Example 1: java manipulate alphabet list

String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";int indexOfLetterD = alphabet.indexOf("D");//indexOfLetterD equals 3

Example 2: java manipulate alphabet list

String usernameInDatabase = "modernNerd";String passwordInDatabase = "mN123Java";String providedUsername = "modernnerd";String providedPassword = "mN123Java";if(providedUsername.equalsIgnoreCase(usernameInDatabase)){    //successful username comparison    //check the provided password    //this will fail    //if("mn123java".equals(passwordInDatabase)){}        //this will pass    if(providedPassword.equals(passwordInDatabase)){        System.out.println("Success! You are logged in.");    } else {        System.out.println("Wrong password. Try again.");    }} else {    //user provided wrong username    System.out.println("Wrong username. Try again.");}

Example 3: java manipulate alphabet list

String middle3 = (string.length < 3) ? null : string.substring(string.length / 2 - 1), string.length / 2 + 2);

Example 4: java manipulate alphabet list

String middle3 = (string.length() < 3) ? null : 
              string.substring(string.length() / 2 - 1, string.length() / 2 + 2);

Example 5: java manipulate alphabet list

for (int i = 'A'; i <= 'Z'; i++)
    for (fileName: fileNameList) {
        if ((int)fileName.charAt(0) == i) {
            AlphabetList.add((char)i);
        }
    }
}

Tags:

Java Example