Mon Oct 22, 2012 12:33 pm
import java.util.Arrays;
import java.util.List;
public class ArraysWork {
public static void main(String[] args) {
// Strings array
String cityStrings[] = {"NewYork", "Toronto", "Delhi", "Cairo"};
// Integers array
Integer numbers[] = {4, 3, 11};
// List references
List listStrings = null;
List listIntegers = null;
// Convert strings array to list object
listStrings = Arrays.asList(cityStrings);
System.out.println("Size of the strings list: "+listStrings.size());
System.out.println("Value at index 1->"+ listStrings.get(1));
System.out.println("Calling toString function :"+listStrings);
// Convert numbers array to list object
listIntegers = Arrays.asList(numbers);
System.out.println("Size of the numbers list: " + listIntegers.size());
System.out.println("Value at index 1->"+listIntegers.get(1));
System.out.println("Calling toString function :"+ listIntegers);
}
}
Size of the strings list: 4
Value at index 1->Toronto
Calling toString function :[NewYork, Toronto, Delhi, Cairo]
Size of the numbers list: 3
Value at index 1->3
Calling toString function :[4, 3, 11]
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.