Java examples for java.lang:byte Array
checks if two byte-arrays contain the same bytes
/******************************************************************************* * Copyright (c) 2008 JCrypTool Team and Contributors * /* w w w . java 2 s . com*/ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse * Public License v1.0 which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html *******************************************************************************/ //package com.java2s; public class Main { public static void main(String[] argv) throws Exception { byte[] a = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; byte[] b = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 }; System.out.println(equals(a, b)); } /** * checks if two byte-arrays contain the same bytes * * @param a - first byte-array * @param b - second byte-array * * @return true or false */ public static boolean equals(byte[] a, byte[] b) { if (a.length != b.length) { return false; } for (int i = 0; i < a.length; i++) { if (a[i] != b[i]) { return false; } } return true; } }