public class m1 {
public static void main(String[] args) {
String str = "abc";
if (str == null) {
//ifn
}
if (str != null) {
//inn
}
if (str == null) {
//str.null
}
if (str != null) {
//str.notnull
//str.nn
}
if ("abc" == null) {
//"abc".null
}
}
}
3、遍历数组或集合
数组或集合变量.fori:for循环
数组或集合变量.for:增强for循环
数组或集合变量.forr:反向for循环
数组或集合变量.iter:增强for循环遍历数组或集合
public static void main(String[] args) {
int[] arr = new int[]{1,2,3,4};
for (int i = 0; i < arr.length; i++) {
//arr.fori 一般for循环
}
for (int i = arr.length - 1; i >= 0; i--) {
//arr.forr 倒序for循环
}
for (int i : arr) {
//arr.for 增强for循环
}
for (int i : arr) {
//arr.iter: 和arr.for 的效果一样
}
=======================================================================
ArrayList arrayList = new ArrayList();
for (int i = 0; i < arrayList.size(); i++) {
//arrayList.fori
}
for (int i = arrayList.size() - 1; i >= 0; i--) {
//arrayList.forr
}
for (Object o : arrayList) {
//arrayList.for
}
for (Object o : arrayList) {
//arrayList.iter
}
for (int i = 0; i < ; i++) {
//fori
}
}