Java – Program Integer Array Sorting

package JavaPrograms;
import java.util.Arrays;

public class IntArraySorting   {

	  public static void main(String[] args) {
	    int arrayList[] = {1,2,4,5,9,3,6,22,33};

	    int len = arrayList.length;

	    Arrays.sort(arrayList);

	    for(int i=0;i<len; i++)
	    {
	    	System.out.print(arrayList[i] +"\n");
	    }

	    Arrays.sort(arrayList);  // sort method used to sort the array contents .
	    System.out.println("2nd Highest number: " + Arrays.asList(arrayList[len-2]));
	    int index = Arrays.binarySearch(arrayList, 33);

	    for (int j=0;j<len; j++)
	    {
	    	int index1 = Arrays.binarySearch(arrayList, arrayList[j]);    	
	    	if(index== index1)
			    {
			    	System.out.println("Number is present and index value is " + index);
			    	break;
			    }
	    	else
	    	{
	    		if(j==len-1)
	    		{
	    			System.out.println("Number is not present");
	    		}
	    }
	    }
	  }
	}

 

You might also like More from author

Loading...