Array Class in JAVA | Using Array Class in JAVA.(Arrays.fill | Arrays.sort | Arrays.equals | Arrays.binarySearch in JAVA)
CODING:
import java.util.*;
class Array
{
public static void main(String[] args)
{
int[] a={4,8,12,45,26,67,48,71};
int i;
System.out.print("Initialize of Array A->");
for(i=0;i<a.length;i++)
{
System.out.print(" " + a[i]);
}
int[] b=new int[8];
Arrays.fill(b,313);
System.out.print("\nFill All Element of Array B->");
for(i=0;i<b.length;i++)
{
System.out.print(" " + b[i]);
}
Arrays.sort(a,0,8);//also use Arrays.sort(type[] a)
System.out.print("\nAfter Sorting Array A->");
for(i=0;i<a.length;i++)
{
System.out.print(" " + a[i]);
}
boolean t=Arrays.equals(a,b);
if(t==true){
System.out.print("\nBoth Array Same Type are Equal to one another.");
}else{
System.out.print("\nBoth Array Not Same Type are Equal to one another.");
}
int index=Arrays.binarySearch(a,26);
if(index>=0){
System.out.print("\n26 is indexed " + index);
}else{
System.out.print("\n26 not Found.");
}
}
}
import java.util.*;
class Array
{
public static void main(String[] args)
{
int[] a={4,8,12,45,26,67,48,71};
int i;
System.out.print("Initialize of Array A->");
for(i=0;i<a.length;i++)
{
System.out.print(" " + a[i]);
}
int[] b=new int[8];
Arrays.fill(b,313);
System.out.print("\nFill All Element of Array B->");
for(i=0;i<b.length;i++)
{
System.out.print(" " + b[i]);
}
Arrays.sort(a,0,8);//also use Arrays.sort(type[] a)
System.out.print("\nAfter Sorting Array A->");
for(i=0;i<a.length;i++)
{
System.out.print(" " + a[i]);
}
boolean t=Arrays.equals(a,b);
if(t==true){
System.out.print("\nBoth Array Same Type are Equal to one another.");
}else{
System.out.print("\nBoth Array Not Same Type are Equal to one another.");
}
int index=Arrays.binarySearch(a,26);
if(index>=0){
System.out.print("\n26 is indexed " + index);
}else{
System.out.print("\n26 not Found.");
}
}
}
Comments
Post a Comment