GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Friday, December 17, 2010

Java - Array

Array is the most basic data structure in Java.
To initialize it, you can use one of:

>> String[] names = new String[]{"steve jobs","larry page","sergey brin"};

or

>> String cities[] = new String[]{"denpasar","singapore","san jose"};

or the compact way

>> String countries[] = {"indonesia","germany","filiine"};

or the more conventional way

>> String fruit[] = new String[10];
>> fruit[0] = "apple";
>> fruit[2] = "banana";
>> fruit[5] = "orange";


There's just one attribute that so useful, that's to get the size of the array:

>> int count = names.length;

for auto iterate, use:
>> for(String s: names){
>>    System.out.println(s);
>> }


Share/Bookmark

No comments:

Post a Comment