Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fefong/java_ifElse

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java Conditional IF/Else

Example Application: Conditional: IF/ELSE

Simple conditional IF and ELSE

int value = 1;
if (value == 1) {
	// TODO
	System.out.println("Value is 1");

} else {
	// TODO
	System.out.println("Value is not 1");

}

IF conditional with multiple ELSE

int value = 1;
if (value < 1) {
	// TODO
	System.out.println("Value is less than 1");

} else if (value == 1) {
	// TODO
	System.out.println("Value is 1");

} else if (value == 2) {
	// TODO
	System.out.println("Value is 2");

} else if (value > 2) {
	// TODO
	System.out.println("Value is greater than 2");

}

IF with Boolean

boolean bVal = true;

if (bVal) {
	// TODO
	System.out.println("TRUE");

} else {
	// TODO
	System.out.println("FALSE");

}

IF with "!".

boolean bVal = true;
if (!bVal) {
	// TODO
	System.out.println("TRUE");
} else {
	// TODO
	System.out.println("FALSE");
}

IF String Equals.

String sVal = "wwww.google.com";
if (sVal.equals("wwww.google.com")) {
	// TODO
}

IF String Equals Ignore Case Sensitive.

String sVal = "wwww.google.com";
if (sVal.equalsIgnoreCase("WWW.GOOGLE.COM")) {
	// TODO
}

IF String starts with the specified prefix.

String sVal = "wwww.google.com";
if (sVal.startsWith("www")) {
	// TODO
}

IF String end with the specified prefix.

String sVal = "wwww.google.com";
if (sVal.endsWith(".com")) {
	// TODO
}

IF String using &&

String sVal = "wwww.google.com";
if (sVal.startsWith("www") && sVal.endsWith(".com")) {
	// TODO
}

IF String using ||

String sVal = "wwww.google.com";
if (sVal.startsWith("www") || sVal.endsWith(".com")) {
	// TODO
}

IF String is Empty value.

String sVal = "wwww.google.com";
if (sVal.isEmpty()) {
	// TODO
}

If conditional (ternary)

Sintax conditional (ternary)

condition ? exprIfTrue : exprIfFalse

boolean bVal = true;
String value = "This boolean is: "+ (bVal==true?"True":"False");

Some links for more in depth learning

Releases

No releases published

Packages

No packages published

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.