-5

Here is code to detect a string containing uppercase letters but not sure whether its performs the best. Any improvement would be great help as im applying to huge chuck of data.

public static boolean testAllUpperCase(String str){
    for(int i=0; i<str.length(); i++){
        char c = str.charAt(i);
        if(c >= 49 && c <= 102) {
            return false;
        }
    }
    //str.charAt(index)
    return true;
}
Ajay Deepak
  • 471
  • 5
  • 9
  • 2
    How are *we* meant to know the interviewer's intention? (I assume this is Java, by the way? You haven't said... or bothered to format your code.) – Jon Skeet Jul 20 '14 at 19:37
  • You know, you could just run this code and see what happens... Take less time than posting a question and waiting for someone to do it for you. – takendarkk Jul 20 '14 at 19:59
  • It *will* create a new String and leave it's reference in `obj`. Doing so is pointless, though. (If you claim to know Java you should know this cold.) – Hot Licks Jul 20 '14 at 20:01

1 Answers1

0

Yes it is possible. The intent is to test whether the interviewee understands the concept of inheritance in Java- "String is an Object"

Khary Mendez
  • 1,818
  • 1
  • 14
  • 18