Execution order of "or" (||) condition in java

First look at the following code:

String str = "12";
if(str.length()<5 || !str.substring(0,3).equals("780")) System.out.println("网点号不符合规范");

The execution result is:

网点号不符合规范

Let's look at the following code 2:

String str = "12";
if(!str.substring(0,3).equals("780")) System.out.println("网点号不符合规范");

The execution result is:

java.lang.StringIndexOutOfBoundsException: String index out of range: 3
Process finished with exit code -1

Therefore, we can get the following results:
Java's "or" is executed sequentially. If the first condition has reached the effect of judging the entire expression, then the remaining conditions will not be executed (otherwise, the first code will also report StringIndexOutOfBoundsException)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325990249&siteId=291194637