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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -