• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in using boolean variable  RSS feed

 
Pooja Patole
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I have a code in which i want to check if the projects I have deleted from a list exist even after deletion . So i used a boolean variable. I am getting the correct result but still i think I haven't done it right.Please help me as even after debugging I dint get the mistake.
 
John Jai
Rancher
Posts: 1776
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Equals of String should be compared using the equals() method and not using == or != operators. It compares the references rather than the String content.
 
Pooja Patole
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Jai wrote:Equals of String should be compared using the equals() method and not using == or != operators. It compares the references rather than the String content.


Okay I tried that .. I want to know when i debugged the program , the If condition was checked and even when it found that the values were same it entered the if loop . But I feel that when the values are same it should not enter the if , instead should execute the else statement right??
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you paste the piece of code for which you are asking the question? I am not sure you are asking on changed one or the last posted code.



Also note that break statement is not present inside the scope of else block. You haven't specified the { and } for your else and hence the enhanced for loop iterates only once.
 
Pooja Patole
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Can you please tell me what this code does? I have written it but now am confused..

Pooja
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you are trying to write a JUnit test case. you should only be telling us what's your intent of the code and what does expectedProjectNames and actualProjectNames contain.

Try to traverse every step as a compiler and try to understand it.
 
Pooja Patole
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay ! will do that ..Thanks for your help
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!