“Java Shorthand If” Code-Antworten

Java eine Zeile, wenn sonst

statement ? true 	: 	false
  ^		  |	 ^			  ^
condition |   (instruction)
  		  |  If the statement:  
  		  |	is true | is false
--------------------------------------------------------------------------------
 Example:
int i = 10;

String out = i > 8 ? "Bigger than Eight!" : "Smaller than Eight!";
System.out.println(out);
TB__privi

Java Shorthand If

//Clear example with good readabilty
String var = "Text";
String shortHand = (var.equals("Text") ? "Returns this if true" : "Returns this if false");

//Other example that is less readable
int var = 9;
int shortHand = var == 9 ? 1 : var++;

//Pseudo code
// CONDITION ? returns when true : returns when false
Cookie_n00b

Java Shorthand If


name = ((city.getName() == null) ? "N/A" : city.getName());

Nervous Nightingale

Ähnliche Antworten wie “Java Shorthand If”

Fragen ähnlich wie “Java Shorthand If”

Weitere verwandte Antworten zu “Java Shorthand If” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen