-8

I came across a code snippet online that used a notation that from what I gather seems to do a comparison and then returns back possible multiple outputs. I am still confused about it, even after research. Can someone re-write the code snippet to an equivalent, more basic version so that I can make sure I am understanding what I am seeing?

int mPart = i < mParts.length ? Integer.parseInt(mParts[i]) : 0;

Thanks in advance!

portfoliobuilder
  • 7,556
  • 14
  • 76
  • 136

1 Answers1

1

This is ternary IF operator. This line is equal to

int mPart;
if(i < mParts.length) {
   mPart = Integer.parseInt(mParts[i]);
} else {
   mPart = 0;
}
dpassy
  • 363
  • 1
  • 10