List of usage examples for java.util Arrays equals
public static boolean equals(Object[] a, Object[] a2)
From source file:Main.java
public static void main(String[] args) { float[] arr1 = new float[] { 1f, 123f }; float[] arr2 = new float[] { 1f, 123f, 22f, 4f }; float[] arr3 = new float[] { 1f, 123f }; System.out.println(Arrays.equals(arr1, arr2)); System.out.println(Arrays.equals(arr1, arr3)); }
From source file:Main.java
public static void main(String[] args) { Object[] arr1 = new Object[] { 1, 123 }; Object[] arr2 = new Object[] { 1, 123, 22, 4 }; Object[] arr3 = new Object[] { 1, 123 }; System.out.println(Arrays.equals(arr1, arr2)); System.out.println(Arrays.equals(arr1, arr3)); }
From source file:Main.java
public static void main(String[] args) { double[] arr1 = new double[] { 1.2, 1.23 }; double[] arr2 = new double[] { 1.2, 1.23 }; double[] arr3 = new double[] { 1.23, 1.2 }; System.out.println(Arrays.equals(arr1, arr2)); System.out.println(Arrays.equals(arr1, arr3)); }
From source file:Main.java
public static void main(String[] args) { short[] arr1 = new short[] { 4, 1, 15, 6 }; short[] arr2 = new short[] { 4, 1, 15, 6 }; short[] arr3 = new short[] { 3, 1, 6, 12 }; System.out.println(Arrays.equals(arr1, arr2)); System.out.println(Arrays.equals(arr2, arr3)); }
From source file:Main.java
public static void main(String[] args) { long[] arr1 = new long[] { 1, 23, 12, 45, 54 }; long[] arr2 = new long[] { 1, 23, 12, 45, 54, 67, 78 }; long[] arr3 = new long[] { 1, 23, 12, 45, 54, 67, 78 }; System.out.println(Arrays.equals(arr1, arr2)); System.out.println(Arrays.equals(arr2, arr3)); }
From source file:Main.java
public static void main(String[] args) { String str = "Result"; String str1 = "rEsLtu"; char[] firstString = str.toLowerCase().toCharArray(); char[] secondString = str1.toLowerCase().toCharArray(); Arrays.sort(firstString);/*from w w w.j av a2 s .c o m*/ Arrays.sort(secondString); if (Arrays.equals(firstString, secondString) == true) { System.out.println("same"); } else { System.out.println("different"); } }
From source file:Main.java
public static void main(String[] args) { Console console = System.console(); if (console == null) { System.out.println("Console is not available"); System.exit(1);/* ww w .ja va2 s . co m*/ } char[] password = "java2s.com".toCharArray(); char[] passwordEntered = console.readPassword("Enter password: "); if (Arrays.equals(password, passwordEntered)) { System.out.println("\n Access granted \n"); Arrays.fill(password, ' '); Arrays.fill(passwordEntered, ' '); System.out.println("OK ..."); } else { System.out.println("Access denied"); System.exit(1); } }
From source file:PasswordPromptingDemo.java
public static void main(String[] args) { Console console = System.console(); if (console == null) { System.out.println("Console is not available"); System.exit(1);// ww w . j a va 2 s.c o m } char[] password = "mustang".toCharArray(); char[] passwordEntered = console.readPassword("Enter password: "); if (Arrays.equals(password, passwordEntered)) { System.out.println("\n Access granted \n"); Arrays.fill(password, ' '); Arrays.fill(passwordEntered, ' '); System.out.println("OK ..."); } else { System.out.println("Access denied"); System.exit(1); } }
From source file:Main.java
public static void main(String args[]) { List<String[]> left = new ArrayList<String[]>(); left.add(new String[] { "one", "two" }); List<String[]> right = new ArrayList<String[]>(); right.add(new String[] { "one", "two" }); java.util.Iterator<String[]> leftIterator = left.iterator(); java.util.Iterator<String[]> rightIterator = right.iterator(); if (left.size() != right.size()) { System.out.println("not equal"); }//from w w w . j a va2 s. co m while (leftIterator.hasNext()) { if (Arrays.equals(leftIterator.next(), rightIterator.next())) continue; else { System.out.print("not equal"); break; } } }
From source file:ArraysTester.java
public static void main(String[] args) { ArraysTester tester = new ArraysTester(50); int[] myArray = tester.get(); // Compare two arrays int[] myOtherArray = tester.get().clone(); if (Arrays.equals(myArray, myOtherArray)) { System.out.println("The two arrays are equal!"); } else {//from w ww .ja va 2s . c om System.out.println("The two arrays are not equal!"); } // Fill up some values Arrays.fill(myOtherArray, 2, 10, new Double(Math.PI).intValue()); myArray[30] = 98; // Print array, as is System.out.println("Here's the unsorted array..."); System.out.println(Arrays.toString(myArray)); System.out.println(); // Sort the array Arrays.sort(myArray); // print array, sorted System.out.println("Here's the sorted array..."); System.out.println(Arrays.toString(myArray)); System.out.println(); // Get the index of a particular value int index = Arrays.binarySearch(myArray, 98); System.out.println("98 is located in the array at index " + index); String[][] ticTacToe = { { "X", "O", "O" }, { "O", "X", "X" }, { "X", "O", "X" } }; System.out.println(Arrays.deepToString(ticTacToe)); String[][] ticTacToe2 = { { "O", "O", "X" }, { "O", "X", "X" }, { "X", "O", "X" } }; String[][] ticTacToe3 = { { "X", "O", "O" }, { "O", "X", "X" }, { "X", "O", "X" } }; if (Arrays.deepEquals(ticTacToe, ticTacToe2)) { System.out.println("Boards 1 and 2 are equal."); } else { System.out.println("Boards 1 and 2 are not equal."); } if (Arrays.deepEquals(ticTacToe, ticTacToe3)) { System.out.println("Boards 1 and 3 are equal."); } else { System.out.println("Boards 1 and 3 are not equal."); } }