java - Writing my own compareToIgnoreCase method -
so i've looked around similar question day or 2 , seems new topic. little project, i'm trying hand write own comparetoignorecase() method without using api strings. in program, user enters string , class definition converts string char array. user enter string , compare first string entered. here compareto()
method wrote. question is, how edit ignore case while comparing.
public int compareto(mystring anothermystring) { if(anothermystring.sequence[i] > 0) { return 1; } else if(anothermystring.sequence[i] == 0) { return 0; } else { return -1; } }
assuming you're ok using java.lang.character
, 1 possible solution ignore case convert each char lowercase before comparing them:
char1 = character.tolowercase(char1); char2 = character.tolowercase(char2); // compare char1, char2
Comments
Post a Comment