import java.util.Arrays;
import java.util.List;
public class Eric {
public static void main(String[] args) {
/** looping through array an array **/
String [] myValues = {"1", "2", "3", "4", "5"};
String valueCollector = "";
for(int x=0;x<myValues.length;x++){
valueCollector = valueCollector + ", " + myValues[x];
}
System.out.println("Values in simple loop=" + valueCollector);
/** Java 1.5 foreach style loop **/
valueCollector = "";
for(String temp : myValues){
valueCollector = valueCollector + ", " + temp;
}
System.out.println("Values in foreach loop=" + valueCollector);
/** Turn primitive array into Array List
* notice when I define the List (which is an interace)
* I tell it the receiving type in the List is
* String because the Array is of Strings
* **/
valueCollector = "";
List<String> keyValues = Arrays.asList(myValues);
for(String temp : keyValues){
valueCollector = valueCollector + ", " + temp;
}
System.out.println("Values using java.util.Arrays loop=" + valueCollector);
/** Since List is a known collection it has an internal toString()
* you can skip the actual loop since some wrote it inside the List.toString() **/
System.out.println("Values using java.util.Arrays NO LOOP=" + keyValues);
}
}