Arrays - Basic Java Tutorials For Selenium WebDriver

What is Array?
As nosotros convey learnt inwards my postal service nearly DIFFERENT DATA TYPES, We tin shop values inwards variables based on type of information similar int i=5; double d = 12.254; etc inwards coffee software development. Now if you lot wants to shop multiple values (10 or fifteen or to a greater extent than dissimilar values) inwards dissimilar variables in addition to thus it volition hold out overhead for you lot to practise in addition to initialize different variables for each value. In this situation, you lot tin purpose array to shop multiple dissimilar values inwards array. An array tin store multiple value of same information type(int, char, String) at the same fourth dimension in addition to each stored information place has unique Index. There are 2 types of array inwards java software evolution language. One Dimensional Array and Two Dimensional Array.

One Dimensional Array


Above given Image describes ane dimensional array having ane row of data. One dimensional array is but similar spreadsheet amongst information inwards ane row. As shown inwards to a higher house Image, Index of array Is starting from 0. Means value 10 has Index 0, 12 has Index 1 in addition to thus on in addition to each value tin hold out Identified yesteryear Its Index. We tin practise in addition to Initialize values In array every bit shown In bellow given example.
public degree Array_Example {   populace static void main(String[] args) {   int a[] = novel int[6]; //Array annunciation in addition to Creation. vi is length of array.   a[0] = 10; //initialize 1st array element   a[1] = 12; //initialize sec array element   a[2] = 48; //initialize tertiary array element   a[3] = 17; //initialize quaternary array element   a[4] = 5;  //initialize fifth array element   a[5] = 49; //initialize sixth array element      for(int i=0; i<a.length; i++){   System.out.println(a[i]);   }  }  }

In to a higher house example, Length of array a[] is vi in addition to information type of array is int. Means nosotros tin shop max vi integer values inwards this array of coffee software evolution language. for loop helps to impress value of each array cell. a.length volition supply length of array. When you lot volition run to a higher house event inwards eclipse, You volition acquire bellow given number inwards console.
a[0] Holds 10 a[1] Holds 12 a[2] Holds 48 a[3] Holds 17 a[4] Holds v a[5] Holds 49

Another means of creating in addition to initializing same ane dimensional array is every bit shown bellow.
int a[] = {10,12,48,17,5,49};

Two Dimensional Array

Tow dimensional array inwards coffee software evolution linguistic communication is but similar spreadsheet amongst multiple rows in addition to columns having dissimilar information inwards each cell. Each prison theatre mobile telephone volition hold out Identified yesteryear it's unique row in addition to column Index combination(Example str[5][3]). We tin purpose 2 dimensional array to shop user id in addition to password of dissimilar users every bit shown inwards to a higher house Image. For to a higher house given event Image, We tin practise in addition to initialize values inwards 2 dimensional array every bit shown inwards bellow given example.
public degree Twodimarray {   populace static void main(String[] args) {   String str[][] = novel String[3][2]; //3 rows, 2 columns   str[0][0]="User1";   str[1][0]="User2";   str[2][0]="User3";   str[0][1]="Password1";   str[1][1]="Password2";   str[2][1]="Password3";      for(int i=0; i<str.length; i++){//This for loop volition hold out full executed iii times.    for(int j=0; j<str[i].length; j++){//This for loop volition hold out executed for 2 fourth dimension on every iteration.     System.out.println(str[i][j]);    }   }  } }

When you lot volition run this event inwards eclipse, It volition supply bellow given number inwards console.
User1 Password1 User2 Password2 User3 Password3

Other means of creating in addition to initializing same 2 dimensional array is every bit shown bellow.
String str[][] = {{"User1","Password1"},{"User2","Password2"},{"User3","Password3"}};

More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM

http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post