Here you can find the source of startsWith(CharSequence source, CharSequence search)
public static boolean startsWith(CharSequence source, CharSequence search)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); public class Main { /**//from w w w. j a v a 2 s. co m * Returns true if the source sequence starts with the search sequence. This is * simply a call to {@link #containsAt} with location 0. */ public static boolean startsWith(CharSequence source, CharSequence search) { return containsAt(source, search, 0); } /** * Returns true of the passed source sequence contains the specified search * sequence starting at the given location. Will return false if either the * source or search sequences are null, or the specified location is outside * of the source sequence (either high or low). */ public static boolean containsAt(CharSequence source, CharSequence search, int loc) { if (source == null) return false; if (search == null) return false; if (loc < 0) return false; if (loc + search.length() > source.length()) return false; for (int ii = 0; ii < search.length(); ii++) { if (source.charAt(loc + ii) != search.charAt(ii)) return false; } return true; } }