jeudi 19 février 2015

Comparing chars within Java StringBuffer

I want to check if the char at a certain index in a StringBuffer is equal to a char. I am getting an error, how do I compare them? Here's my code:



//I have an established StringBuffer called stringbuffer

char[] mychar = null;
for(int i = 0; i < stringbuffer.length(); ++i){
if(stringbuffer.charAt(i) != " "){
mychar[i] = stringbuffer.charAt(i);
}
}


The error I am getting is incompatible operand types char and String. Not sure why, because I am comparing a char of a StringBuffer, not a String or StringBuffer.


Aucun commentaire:

Enregistrer un commentaire