• Post Reply Bookmark Topic Watch Topic
  • New Topic

understand what !=-1 mean  RSS feed

 
Chris Kislow
Greenhorn
Posts: 21
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this line of code


I understand all but why do i see != -1 instead of null
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris Kislow wrote:
I understand all but why do i see != -1 instead of null


The LHS (left hand side) of the comparison operator resolves to an int value. So, why do you think that the RHS (right hand side) should resolve to an instance? And hence, compared to null?

Henry
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should never write code that is concatenated like that (unless you catch the possible Exception).

What happens if the lintToken[0] does not contain any commas?
 
Brian Dady
Greenhorn
Posts: 4
Java jQuery PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
indexOf() returns an int, so you will need to compare it to another int. You would only be testing for null if you were comparing to an object.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!