Here you can find the source of startsWith(char[] str1, String str2)
public static final boolean startsWith(char[] str1, String str2)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2015 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:// ww w .j av a 2s . co m * IBM Corporation - initial API and implementation * Andrew Ferguson (Symbian) * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) *******************************************************************************/ public class Main { /** * Returns {@code true} if a prefix of the character array is the same as contents * of a string. * @since 5.4 */ public static final boolean startsWith(char[] str1, String str2) { int len = str2.length(); if (str1.length < len) return false; for (int i = 0; i < len; i++) { if (str1[i] != str2.charAt(i)) { return false; } } return true; } }