instanceof 运算符仅用于对象引用变量。该运算符检查对象是否为特定类型(类类型或接口类型)。示例public class Test { public static void main(String args[]) { String name = "James"; boolean result = name instanceof String; System.out.println(result); } }输出true
java.util.Arrays 类的 sort(int[]) 方法将指定的整数数组排序为升序数值顺序。示例import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { int iArr[] = {2, 1, 9, 6, 4}; for (int number : iArr) { System.out.println("Number = " + number); } Arrays.sort(iArr); System.out.println("The sorted int array is:"); for (int number : iArr) { System.out.println("Number = " + number); } } }输出Number = 2 Number = 1 Number = 9 Number = 6 Number = 4 The sorted int array is: Number = 1 Number = 2 Number = 4 Number = 6 Number = 9
条件运算符也称为三元运算符。此运算符包含三个操作数,用于评估布尔表达式。运算符的目标是决定应为变量分配哪个值。运算符写成:variable x = (expression)? value if true: value if false示例public class Test { public static void main(String args[]) { int a, b; a = 10; b = (a == 1) ? 20: 30; System.out.println("Value of b is: " + b); b = (a == 10) ? 20: 30; System.out.println(“Value of b is: " + b); } }输出Value of b is: 30 Value of b is: 20