Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

if then for?  RSS feed

 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does this makes sense?

version 1:


Or can I do it with that for the same effect:

version 2:


I mean, when myMap is empty, then the for-Loop does not excecute. Does this make Java for me or should I do the first version? Whats the difference?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are equivalent. In fact, a smart enough compiler or JRE would be able to optimize them down to the same thing, but since isEmpty() is a method and could potentially do anything I wouldn't plan on it - a number of sub-optimizations would all have to kick in before it became safe to assume that isEmpty() is redundant here.
 
nimo frey
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay thanks, so I take version 2.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!