Skip to content

uppercase string array without using standard library functions, which makes the algorithm faster by few milliseconds-(Java/src/main/java/com/thealgorithms/strings/Upper.java ) #3445

@SantoshInchalakaranji

Description

@SantoshInchalakaranji
  1. In the above mentioned algorithm the author used the library functions to check lowercase letters and to convert it to uppercase. which will be time consuming and makes the algorithm again depend on the external built in functions. it can be speeded up by using ascci values and independent of standard libraries.`

  2. public static String toUpperCase(String s) {
    if (s == null || "".equals(s)) {
    return s;
    }
    char[] values = s.toCharArray();
    for (int i = 0; i < values.length; ++i) {
    if ( lHere used the library functions

             Character.isLetter(values[i]) &&
             Character.isLowerCase(values[i])
    

//these above 2 checks can be reduced as

values[i]>='a' && values[i]<='z'
) {

              // here used library functions
            values[i] = Character.toUpperCase(values[i]);

this above line can be changed as

// values[i] = (char) (values[i] - 32);
}
}
return new String(values);
}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions