1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
/* Compare Two Java boolean Arrays Example This java example shows how to compare two boolean arrays for equality using Arrays.equals method. */ import java.util.Arrays; public class CompareBooleanArraysExample { public static void main(String[] args) { //create boolean arrays boolean[] blnArray1 = new boolean[]{true,false,true}; boolean[] blnArray2 = new boolean[]{true,false,true}; /* To compare two boolean arrays use, static boolean equals(boolean array1[], boolean array2[]) method of Arrays class. It returns true if both arrays are equal. Arrays are considered as equal if they contain same elements in same order. */ boolean blnResult = Arrays.equals(blnArray1,blnArray2); System.out.println("Are two boolean arrays equal ? : " + blnResult); /* Please note that two boolean array references pointing to null are considered as equal. */ } } /* Output of the program would be Are two boolean arrays equal ? : true */ |
How i can sort alphabetically this merged two Arrays?plz
String A[] = { “Joseph”,”Ariana”,”Xena”,”Rene”,”Peter”,”Diana”,”Rihanna”};
String B[] = {“Madona”,”Diddy”,”Joe”,”Alice”};
List<string> list = new ArrayList(Arrays.asList(A));
list.addAll(Arrays.asList(B));
Object[] C = list.toArray();
System.out.println(Arrays.toString(C));
}
String A[] = new String[] { “Joseph”, “Ariana”, “Xena”, “Rene”, “Peter”, “Diana”, “Rihanna”};
String B[] = new String[] { “Madona”, “Diddy”, “Joe”, “Alice”};
ArrayList<string> list = new ArrayList<string>();
for(int i = 0; i < A.length; i++)
list.add(A[i]);
for(int i = 0; i < B.length; i++)
list.add(B[i]);
Collections.sort(list);
for(String str : list)
System.out.println(str);