Here you can find the source of startsWith(List left, List right, boolean equals)
public static boolean startsWith(List left, List right, boolean equals)
//package com.java2s; /******************************************************************************* * Copyright (c) 2000, 2010 IBM Corporation and others. * 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 * * Contributors:// w w w .ja va 2 s. c om * IBM Corporation - initial API and implementation *******************************************************************************/ import java.util.List; public class Main { public static boolean startsWith(List left, List right, boolean equals) { if (left == null || right == null) { return false; } else { int l = left.size(); int r = right.size(); if (r > l || !equals && r == l) { return false; } for (int i = 0; i < r; i++) { if (!equals(left.get(i), right.get(i))) { return false; } } return true; } } public static boolean startsWith(Object[] left, Object[] right, boolean equals) { if (left == null || right == null) { return false; } else { int l = left.length; int r = right.length; if (r > l || !equals && r == l) { return false; } for (int i = 0; i < r; i++) { if (!equals(left[i], right[i])) { return false; } } return true; } } public static boolean equals(boolean left, boolean right) { return left == right; } public static boolean equals(int left, int right) { return left == right; } public static boolean equals(Object left, Object right) { return left == null ? right == null : ((right != null) && left.equals(right)); } /** * Tests whether two arrays of objects are equal to each other. The arrays * must not be <code>null</code>, but their elements may be * <code>null</code>. * * @param leftArray * The left array to compare; may be <code>null</code>, and * may be empty and may contain <code>null</code> elements. * @param rightArray * The right array to compare; may be <code>null</code>, and * may be empty and may contain <code>null</code> elements. * @return <code>true</code> if the arrays are equal length and the * elements at the same position are equal; <code>false</code> * otherwise. */ public static final boolean equals(final Object[] leftArray, final Object[] rightArray) { if (leftArray == rightArray) { return true; } if (leftArray == null) { return (rightArray == null); } else if (rightArray == null) { return false; } if (leftArray.length != rightArray.length) { return false; } for (int i = 0; i < leftArray.length; i++) { final Object left = leftArray[i]; final Object right = rightArray[i]; final boolean equal = (left == null) ? (right == null) : (left.equals(right)); if (!equal) { return false; } } return true; } }