“Java Shorthand If” Kode Jawaban

java satu baris jika lain

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

Jawaban yang mirip dengan “Java Shorthand If”

Pertanyaan yang mirip dengan “Java Shorthand If”

Lebih banyak jawaban terkait untuk “Java Shorthand If” di Java

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya