Error corrected. I need to add:
Code :str4 = null;
in order to "clear out" what was in it whenever it looped.
Printable View
Error corrected. I need to add:
Code :str4 = null;
in order to "clear out" what was in it whenever it looped.
Glad you figured it out, Due to giving answers out I'm not allowed to post code :(
But congratulations on figuring it out.
It's not that you aren't allowed to post code, it's just that posting full code solutions (especially when your solutions aren't completely correct, like the code you posted in this thread that actually causes Exceptions) isn't actually helpful. Again, I'm not trying to be a jerk, and I understand how fun it can be to solve problems, but it's a lot of work for us moderators to keep track of people who are giving out bad advice.
Say you declare a string
public String str = "";
it will not return as null during the program..
you're simply searching for a blank string.
Its only if you were to declare it at the top like
public String str;
that would display null as you are not initializing any values to it..
So no im not checking if the string is null, Im checking if the string contains anything...
Well, OP must know the difference between == and equals(). So,
== actually tells you if the two object references are refering to the same instance, i.e.
Here the result will be true as both are referencing the same instance.Code :String x="Hello" String y=x; x==y;
But,
here the result will be false because both are referring to the different instances.Code :String x="Hello"; String y=new String ("Hello"); x==y;
Now come to the equals(). Actually equals() compare the character values of a String object.
Code :String x="Hello"; String y="Hello"; x.equals(y); //True String z=new String(y); x.equals(z);//true But x==z; //False
Hope this will help you alot, understanding the concept.
Thanks