So new to Java it hurts

W

webbedaccess

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;}
}
}
}
 
I

IchBin

webbedaccess said:
Where did I go wrong? should the private variable str be a character,
or should cast?
cast the charAt to a string?
if (!(str.charAt(iToken) == " " )) {

change to this

if (!(str.charAt(iToken) == ' ' )) {

Did not follow you logic but this is the problem..
--


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
I

IchBin

IchBin said:
change to this

if (!(str.charAt(iToken) == ' ' )) {

Did not follow you logic but this is the problem..

You might want to look at the sting command .split(' ')

--


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
I

IchBin

webbedaccess said:
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

Don't cross post..
I answered in another group.


--


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 
N

Noodles Jefferson

webbedaccess took the hamburger, threw it on the grill, and I said "Oh
wow"...
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

<SSCCE>

public class StringSplitter {


public void stringToChars(String s) {

String str = s.trim();
char[] ca = str.toCharArray();

findABlank(ca);

}

public void findABlank(char[] ch) {

boolean hasABlank = false;
int i = 0;

while ( i < ch.length) {

if (ch == ' ') {

hasABlank = true;
System.out.println("Found a blank at index: " + i);
System.out.println("Has a Blank? " + hasABlank);

}

i++;

}

}

public static void main(String[] args) {

StringSplitter ss = new StringSplitter();

ss.stringToChars("A String.");
System.exit(0);

}

}

<SSCCE>

--
Noodles Jefferson
mhm31x9 Smeeter#29 WSD#30
sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM

NP: "The Road to Chicago" -- Thomas Newman (Road to Perdition
Soundtrack)

"Our earth is degenerate in these latter days, bribery and corruption
are common, children no longer obey their parents and the end of the
world is evidently approaching."
--Assyrian clay tablet 2800 B.C.
 
L

Luc The Perverse

IchBin said:
Don't cross post..
I answered in another group.

Cross posting is MUCH better than posting the same question in seperate
groups with seperate threads.

A decent newsreader should be able to mark the message as read in both
groups if you survey both of them, so as not to inconvenience you. And
people reading in only comp.lang.java.programmer might have been interested
to see your reply as well ;)
 
I

IchBin

Luc said:
Cross posting is MUCH better than posting the same question in seperate
groups with seperate threads.

A decent newsreader should be able to mark the message as read in both
groups if you survey both of them, so as not to inconvenience you. And
people reading in only comp.lang.java.programmer might have been interested
to see your reply as well ;)


--
Cool...

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top