Java Array part-01

Structure of array object
Colombo, Sri Lanka
June 10, 2015 12:22pm CST
What is an array? Array is an object. If you want to catch data using one variable. You can use arrays to do it. ....Structure of array..................// int ar[]=new int[3]; Array object has elements and index. Index start with 0, element start with 1 If we think array is a locker. Array elements like chest of drawers. And Index like label of each and every chest of drawers. ....If you want to create an array you should complete three steps. There are..........................// * Declaring * Constructing * Initializing class A{ public static void main(String args[]){ int ar[]=new int[4]; ar[0]=10; ar[1]=20; ar[2]=30; ar[3]=40; } } This array has 4 elements. Array length is equals to elements count. Array index start with 0 so this code max array index is 3 We can get element count using ar.length; method. ....How to print array value.......................................................................................................// So easy if you want to get 2nd element value only you have to do... class A{ public static void main(String args[]){ int ar[]=new int[4]; ar[0]=10; ar[1]=20; ar[2]=30; ar[3]=40; System.out.println(ar[1]); } } Result is-20 This is simple One-D array if you have questions about java or this code I willing to answer any. Thank you!
No responses