Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / December 2005

Tip: Looking for answers? Try searching our database.

So new to Java it hurts

Thread view: 
webbedaccess - 31 Dec 2005 03:46 GMT
Where did I go wrong?  should the private variable str be a character,
or should cast?
cast the charAt to a string?

compile code below I get

incomparable types: char and Java.lang.String

class myGen implements Iterator<String>
  {
     private String str;
     private int iToken;

     public myGen(String s)
     {
       str = s.trim();
       iToken= 0;
     }
     public boolean hasNext()
     {
       // I am trying to return true if there is more; otherwise false
       // I am using a while loop to advance iToken until a non-space
is found.
       // I am checking that iToken < str.length() before I test

       while (iToken < str.length()) {
         if (!(str.charAt(iToken) == " " )) {
             return true;  }
         else {
             return false;}
         }
     }
}
Rob Skedgell - 31 Dec 2005 10:35 GMT
> Where did I go wrong?  should the private variable str be a
> character, or should cast?
[quoted text clipped - 24 lines]
>         while (iToken < str.length()) {
>           if (!(str.charAt(iToken) == " " )) {
                                       ^^^
try replacing with ' ' which is a space (0x20) as a char - " " is a
String containing a single space and String.charAt() returns a char.

>               return true;  }
>           else {
>               return false;}
>           }
>       }
> }

Signature

Rob Skedgell <rob+news@nephelococcygia.demon.co.uk>
From: address is a spamtrap, Reply-To: is valid.
GnuPG/PGP: 7DA3 1579 C0DD 8748 C05A  B984 E2A2 3234 D14B 6DD7



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.