Coding
Coding
System.out.println("Element at index 0:
"
+ anArray[0]);
System.out.println("Element at index 1:
"
+ anArray[1]);
System.out.println("Element at index 2:
"
+ anArray[2]);
System.out.println("Element at index 3:
"
+ anArray[3]);
System.out.println("Element at index 4:
"
+ anArray[4]);
System.out.println("Element at index 5:
"
+ anArray[5]);
System.out.println("Element at index 6:
"
+ anArray[6]);
System.out.println("Element at index 7:
"
+ anArray[7]);
System.out.println("Element at index 8:
"
+ anArray[8]);
System.out.println("Element at index 9:
"
+ anArray[9]);
}
Sorting
Bubble Sort:
The technique we use is called “Bubble Sort” because the bigger
value gradually bubbles their way up to the top of array like air
bubble rising in water, while the
small values sink to the bottom of array.
Deletion
Deleting any element from an array is an O(N) operation. You can do the
following.
1. Initialize i = 0. count = 0.
2. Iterate through array1[] and search for element delete[i].
3. If you encounter an element array1[j] > delete[i], this means that
delete[i] does not exist in array[].
Increment i to check for next element in delete array.
4. If you find an element array1[j] == delete[i], then increment count. and
increment i.
5. Keep copying array1[j] to array1[j - count].
array1[j - count] = array1[j];
6. Continue till the end of array1. At the end, resize array1 to be of size
size - count.
Or
public static void main(String args[]) {
String[] programming = new String[]{"Java", "C+
+", "Perl", "Lisp"};
// Checking an String in String Array by
converting Array To ArrayList
List<String> programmingList =
Arrays.asList(programming);
//Checking does this Array contains Java
ArrayUtils.contains(programming, "Java"));
System.err.println("What is index of Java in
array? " +
ArrayUtils.indexOf(programming, "Java"));
}
}