• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can any one explain this

 
venkat kaka
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i cant understand last line in the following code . can any one explain brefily
public static String removeLeadingZeros(String str){
if (str == null) {
return EaglelinkConstants.EMPTY_SPACE ;
}
char[] chars = str.toCharArray();
int length = str.length();
double value = Double.parseDouble(str);
int index =0;
if(value/10 != 0){
for (; index < length; index++) {
if (chars[index] != '0') {
break;
}
}
}else{
return str;
}
return (index == 0) ? str : str.substring(index);// this line i need explanation.
}
}
what is ? there and what it returns
 
Yogesh Baraskar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is a ternary if operator
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a shorthand for this code.
 
adam Lui
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it looks so absurd but it is totally legal.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by adam lui:
it looks so absurd but it is totally legal.


...and just like if-else-if-else. They can be nested as well. On one side it aids writability on the other language's readability suffers.
 
Xyz Abc
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic