What you could do is to keep track of the smallest one and the second smallest one as you traverse the array from beginning to end. Update them both if you run into something smaller than the second smallest or something bigger than the smallest but less than the second smallest. Hope the following code makes sense:
public class Driver {
public static int MAX_VAL = 1000000;
public static void main(String[] args) {
int[] arr = {2,5,3,6,2,7,43,2,56,2,-1, 1, 5};
int[] smalls = new int[2];
int sm = find(arr, 0, smalls);
System.out.println(sm);
}
public static int find(int[] arr, int index, int [] smalls) {
if(index == 0) {
smalls[0] = arr[index];
smalls[1] = Integer.MAX_VALUE;
find(arr, index+1, smalls);
} else if(index < arr.length){
if(arr[index] < smalls[0]){
smalls[1] = smalls[0];
smalls[0] = arr[index];
} else if(smalls[1] > arr[index]) {
smalls[1] = arr[index];
}
find(arr,index + 1, smalls);
}
return smalls[1];
}
}
Here, index stands for the index of the last element in your 'partial array'. Every recursive step, you examine the first index + 1 elements of your array. Note: small[0] is the SMALLEST element of the partial array and small[1] is the second smallest of the partial array.
For a good treatment of recursion, I recommend you pick up Prolog. This language has no loops and you will rely heavily on recursion.