Showing posts with label Arrays. Show all posts
Showing posts with label Arrays. Show all posts

Sunday, September 24, 2017

Arrays in Java basics for selenium


1. We can assign value to an element in array as shown below:

testing[3] = 43; or all the elements can be defined in a go like shown below:
int[] testing1= {10,20,30,40,50,60,70,80,90,100};

2. We can extract all the values in an array using for each loop as shown below:

 int[] testing1 = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
 for (int test : testing1) {
     System.out.println(test);
 }

3. The same information can be extracted using for loop can be found as shown below:

for (int i = 0; i < testing1.length; i++) {
     System.out.println(testing1[i]);
 }

4. Using length property, we can find the size of any array


e.g. System.out.println(testing1.length)

4. We can pass an array as a parameter to a method, and also return value from a method:

5. We can sort an array in ascending order using sort();

Arrays.sort(testing1);

6. We can fill values in all the array elements using fill() menthod 
Arrays.fill(testing1, 385);

7. We can compare two arrays using arrays.equals

boolean isArrSame = Arrays.equals(testing1, testing);
System.out.println(isArrSame);