国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Java > 正文

java中循環(huán)遍歷

2019-11-06 06:51:36
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

1、while循環(huán)

public class Test {   public static void main(String args[]) {      int x = 10;      while( x < 20 ) {         System.out.PRint("value of x : " + x );         x++;         System.out.print("");      }   }}2、do  while

public class Test {   public static void main(String args[]){      int x = 10;      do{         System.out.print("value of x : " + x );         x++;         System.out.print("");      }while( x < 20 );   }}3、for

public class Test {   public static void main(String args[]) {      for(int x = 10; x < 20; x = x+1) {         System.out.print("value of x : " + x );         System.out.print("");      }   }}
public class Test {   public static void main(String args[]){      int [] numbers = {10, 20, 30, 40, 50};      for(int x : numbers ){         System.out.print( x );         System.out.print(",");      }      System.out.print("");      String [] names ={"James", "Larry", "Tom", "Lacy"};      for( String name : names ) {         System.out.print( name );         System.out.print(",");      }   }}

遍歷List集合的三種方法

List<String> list = new ArrayList<String>();list.add("aaa");list.add("bbb");list.add("ccc");方法一:超級(jí)for循環(huán)遍歷for(String attribute : list) {  System.out.println(attribute);}方法二:對(duì)于ArrayList來(lái)說(shuō)速度比較快, 用for循環(huán), 以size為條件遍歷:for(int i = 0 ; i < list.size() ; i++) {  system.out.println(list.get(i));}方法三:集合類的通用遍歷方式, 從很早的版本就有, 用迭代器迭代Iterator it = list.iterator();while(it.hasNext()) {  System.ou.println(it.next);}


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 三明市| 赤水市| 张家口市| 新营市| 洛阳市| 周宁县| 河北省| 潜江市| 太谷县| 常州市| 沐川县| 大足县| 洱源县| 万源市| 潞西市| 南安市| 扶绥县| 锦屏县| 沂源县| 沭阳县| 尖扎县| 长海县| 温宿县| 如东县| 昆山市| 固始县| 汤阴县| 瑞昌市| 石阡县| 丹寨县| 莎车县| 北海市| 广宗县| 石景山区| 布拖县| 青冈县| 洛川县| 社旗县| 修文县| 花莲县| 苍山县|