Arrays Class - Java

This class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to be viewed as lists.

Methods:

static int binarySearch(array,value) – Search the array for the given value postion
static char[] copyOf(array,length) – copy the array values for the given length
static char[] copyOfRange(array,from,to) – copy the array from and to positions
static boolean equals(array1,array2) – returns true/false
statric void  fill(array,from,to,value) – fills the value between the from-to postions
static void sort(array) – sorts in ascending numerical order
static void paralelSort(array) – The sorting algorithm is a parallel sort-merge that breaks the array into sub-arrays that are themselves sorted and then merged. When the sub-array length reaches a minimum granularity, the sub-array is sorted using the appropriate Arrays.sort method.

static string toString(array) - Returns a string representation of the contents of the specified array

WRITE A PROGRAM ON ARRAYS Class

import java.util.*;
class Sample
{
public static void main(String args[])
{
int a[]=new int[10];
Scanner r=new Scanner(System.in);

  for(int i=0;i<10;i++)
{
System.out.println(“Enter no”);
a[i]=r.nextInt();
}

for(int k in a)
System.out.println(k);

Arrays.sort(a);
for(int k in a)
System.out.println(k);

Arrays.fill(a,2,3,22);
for(int k in a)
System.out.println(k);

int k=Arrays.binarySearch(a,15);
System.out.println(k);

Arrays.paralalSort(a);
for(int k in a)
System.out.println(k);

String s=Arrays.toString(a);
System.out.println(s);
int b[]=Arrays.copyOf(a,5);
if(Arrays.equals(a,b))
System.out.println(“Both are equal”);
else
System.out.println(“Not equals”);

        }

}

 

For
More Explanation
&
Online Classes

Contact Us:
+919885348743