/* * Enhanced for Loop * syntax for (traversal value: set to traverse) {} * Implement the Iterable interface can use enhanced for loop * to iterate through the collection with an enhanced for loop * List s ET implements the iterator interface so you can use the enhanced for loop * Map cannot use the enhanced for loop without implementing the iterator interface, so the enhanced for loop cannot be used to increase the appearance of the For loop instead of the Iterator Navigator window view for bottom The layer uses the iterator * Generic erase * Generics only appear in the source code phase when the compiler does not exist * variable parameter * variable parameter application The scene * realizes the addition of two numbers to achieve the addition of four numbers of three numbers * if you implement multiple methods the logic in these methods is essentially the same. The same is the number of parameters passed can use the variable parameter * variable parameter definition method data type ... The name of the array * is understood to be an array of arrays that store the parameters passed by * public static void Add (int ...).
Nums) {//nums An array array to store the arguments passed over//system.out.println (nums.length);
Traversal array int sum = 0;
for (int i = 0; i < nums.length i++) {sum+=nums[i];
} System.out.println (sum); * NOTE * variable parameters need to be written in the parameter list of the method * cannot be defined separately * Only one variable parameter in the parameter list of a method the variable parameters in the parameter list of the method must be placed at the end of the argument *debug F6 step f 8 End breakpoint followed by breakpoint to next breakpoint * */
//Create list list<string> list = new arraylist<string> ();
List.add ("a");
List.add ("B");
List.add ("C");
Implements the enhanced for loop for (string string:list) {System.out.println (string);
} System.out.println ("1111111111111111");
Using iterators to implement iterator<string> it = List.iterator ();
while (It.hasnext ()) {System.out.println (It.next ()); }
public static void Main (string[) args) {integer[] arr = {1,2,3,4,5};
System.out.println (arrays.tostring (arr));
Realize reverse reverse1 (arr);
You need to use the tool class direct ToString to return the class name and Hashcode returns GetClass (). GetName () + "@" + integer.tohexstring (Hashcode ());
System.out.println (Arr.tostring ());
System.out.println (arrays.tostring (arr));
String[] arr2 = {"1", "2", "3", "4"};
Reverse1 (ARR2);
System.out.println (arrays.tostring (ARR2)); public static <T> void Reverse1 (t[] ar) {* * Swap the first and last elements in the swap position for the second and penultimate swap positions *
Length/2 *//traversal array for (int i = 0; i < AR.LENGTH/2 i++) {/*int temp = ar[0];
Ar[0] = ar[ar.length-1];*/T temp = ar[i];
Ar[i] = ar[ar.length-1-i];
AR[AR.LENGTH-I-1] = temp; }
}
public static void Main (string[) args) {//int ...
Nums; cannot define add (12,3,1);
Add (123,31,1,2); public static void Add (int ...)
Nums) {//nums An array array to store the arguments passed over//system.out.println (nums.length);
Traversal array int sum = 0;
for (int i = 0; i < nums.length i++) {sum+=nums[i];
} System.out.println (sum); }