Error corrected. I need to add:
str4 = null;
in order to "clear out" what was in it whenever it looped.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Error corrected. I need to add:
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.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
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.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
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.String x="Hello" String y=x; x==y;
But,
here the result will be false because both are referring to the different instances.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.
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
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!