Javaリストループとマップループの概要
リストとマップの要約を作成しました。技術的なコンテンツがなかったので、APIをレビューしました。
テスト環境はJUNIT4の下にあり、自分で主要な方法を書いていないと同じになります。
まず、リストには3つのループがあります。
@test public void forlisttest(){list <string> list = new ArrayList <String>(); list.add( "1"); list.add( "2"); list.add( "3"); list.add( "4"); list.add( "5"); // iteratorループは、コレクションのサイズとタイプを知る必要はありません。(@suppresswarnings( "rawTypes")iterator iterator = list.iterator(); iterator.hasnext();){string list =(string)iterator.next(); System.out.println( "01)Iterator for:=============================================================================================== ====================================================================================================== forループの場合、セットのサイズを知る必要があるだけでなく、(int i = 0; i <list.size(); i ++){int i = 0; i <list.size() System.out.println( "03)for ================================================== ===================================================================================================== ====================================================================================================== ===================================================================================================== }}次に、マップの4つのループがあります。
@test public void formaptest(){map <string、string> map = new hashmap <string、string>(); map.put( "01"、 "1"); map.put( "02"、 "2"); map.put( "03"、 "3"); map.put( "04"、 "4"); map.put( "05"、 "5"); <string> keyset = map.keyset()を設定します。 //1.KeySet's foreach Method for(string key:keyset){system.out.println( "1)keyset:" + "key:" + key + "value:" + map.get(key)); } set <entry <string、string >> entryset = map.entryset(); //2.EntrySet Iterator for System.out.println( "02)EntrySet、Iterator:key:" + entry.getKey() + "value:" + entry.getValue()); } // 3。推奨、(エントリ<string、string> entry:entryset){system.out.println( "03)entryset、foreach:key:" + entry.getKey() + "value:" + entry.getValue())の最大容量の最大容量} collection <string> values = map.values(); // 4。 (文字列値:値){System.out.println( "04)値の値のみをループアウトする方法、値のみ、値:" +値); }}読んでくれてありがとう、私はそれがあなたを助けることができることを願っています。このサイトへのご支援ありがとうございます!