以下に示すように:
パッケージcn.jdk.foreach;インポートjava.util.hashmap; import java.util.map; public class foreachtest {public static void main(string [] args){int [] arr = {1,2,3}; a:arr){system.out.println(a+"/t");} system.out.println( "================================================================================= "2"); map.put( "3"、 "3"); map.put( "4"、 "4"); map.put( "5"、 "5"); // map.keyset():Mapのすべてのキーをループします。 map.keyset()セットタイプを返し、トラバーサルのためにセットを強化できます。 for(string key:map.keyset()){string value = map.get(key); //キーシステムを介して対応する値を取得します。<p> Advantages and Disadvantages of Enhancement for</p><p>l can only traverse arrays or collections from beginning to end, but not only part;</p><p>l When traversing List or array, the current element subscript cannot be obtained;</p><p>l Enhancement for is simple to use, which is its only advantage;</p><p>l Enhancement for is a little more convenient than usingイテレーター! </p>
Mapは反復可能なインターフェイスを実装していないため、拡張機能を使用して繰り返して繰り返すことはできません。
上記は、編集者が提起したループ実装方法の拡張Javaの完全な内容です。それがあなたに役立ち、wulin.comをもっとサポートすることを願っています〜