Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

word compare

 
Leonard Stone
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Could anyone help me with this:
I've to store to lists of words from a text file - about 200 in each file. wordlist1(sorted) is stored in an array, wordlist2(unsorted) is read in a word at a time. I'm using a binary search to find a match for a word (searching thru wordlist1 with a word from wordlist2).
If the wordlist2 word starts with a lowercase character and the wordlist1 word starts with a lowercase letter, the word must be printed to the screen with "YES", if the wordlist2 word starts with uppercase, wordlist1 word can be lower or upper and then printed to the screen with a "YES".
and
if the wordlist2 word starts with a lower and the wordlist1 starts with an uppercase,
print the word with "NO".
How do i check the word once i've found it? All the code has to be done without using any java utils.
I would greatly appreciate a coded example, because i've had loads of trouble with the comparing part.
Thanking you in advance.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the String class has these methods that you can use. toLowerCase()/toUpperCase(), startsWith(), equals().
Convert the word to lower or upper case while using equals to do the comparison, then use startsWith to determine what each word starts with.
------------------
Bosun
SCJP for the Java� 2 Platform
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic