1. Differences between & and:
Similarities:
& And & can both be used as operators of logic and, indicating logic and (and ). When the expression on both sides of the operator returns true. The result of the entire operation is true. Otherwise, if either of them is false, the result is false.
Differences:
(1) & it also has the short circuit function, that is, if the first expression is false, the second expression is not calculated. For example, for if (STR! = NULL &&! Str. Equals ("") expression. When STR is null, the following expression is not executed, so nullpointerexception is not thrown if & is changed. If (x = 33 & ++ y> 0) y will increase, if (x = 33 & ++ y> 0) will not increase
(2) & it can also be used as a bitwise operator. When the expressions on both sides of the & operator are not 'boolean' type, & it indicates bitwise AND operation. We usually use 0x0f to perform & operation with an integer, for example, 0x31 & 0x0f returns 0x01.
2. How to jump out of the current multi-nested loop in Java? In Java, to jump out of multiple loops, you can define a label before an External Loop statement and Code Use a break statement with a label to exit the outer loop. For example,
OK:
For (INT I = 0; I <10; I ++) {for (Int J = 0; j <10; j ++) {system. out. println ("I =" + I + ", j =" + J); If (j = 5) Break OK ;}}
In addition, I usually do not use labels. Instead, the results of the outer loop condition expressions can be controlled by the code of the internal loop body. For example, you need to find a number in a two-dimensional array.
Int arr [] [] = {1, 2, 3}, {4, 5, 6, 7}, {9}; Boolean found = false; For (INT I = 0; I <arr. length &&! Found; I ++) {for (Int J = 0; j <arr [I]. length; j ++) {system. out. println ("I =" + I + ", j =" + J); If (ARR [I] [J] = 5) {found = true; break ;}}}