JAVA中“:”的用法详解

1.“str : abc”这样的结构是表示遍历abc集合取出其中的每一个元素

String[] abc = new String[3]{"a","b","c"};
forString 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

猜你喜欢

转载自blog.csdn.net/m983373615/article/details/80249583