1.“str : abc”这样的结构是表示遍历abc集合取出其中的每一个元素
String[] abc = new String[3]{"a","b","c"};
for (String str : abc){
System.out.println(str); //这个地方的冒号就是遍历abc的集合,取出每一个元素
}
2.三目元算符
int a=1;
int b=3;
int i = a>b?3:1;//这个地方的冒号用来选择值,如果a大于b,那么i=3,否则i=1
1.“str : abc”这样的结构是表示遍历abc集合取出其中的每一个元素
String[] abc = new String[3]{"a","b","c"};
for (String str : abc){
System.out.println(str); //这个地方的冒号就是遍历abc的集合,取出每一个元素
}
2.三目元算符
int a=1;
int b=3;
int i = a>b?3:1;//这个地方的冒号用来选择值,如果a大于b,那么i=3,否则i=1