Java String Starts Wtih startsWith(final String source, final String prefix)

Here you can find the source of startsWith(final String source, final String prefix)

Description

Tests if the source string starts with the prefix string.

License

Open Source License

Parameter

Parameter Description
source the source String.
prefix the prefix String.

Return

true, if the source starts with the prefix string.

Declaration

private static boolean startsWith(final String source,
        final String prefix) 

Method Source Code

//package com.java2s;
/*/*ww w  . j av a2 s .  c  o m*/
 * jGnash, a personal finance application
 * Copyright (C) 2001-2017 Craig Cavanaugh
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Tests if the source string starts with the prefix string. Case is
     * ignored.
     *
     * @param source the source String.
     * @param prefix the prefix String.
     * @return true, if the source starts with the prefix string.
     */
    private static boolean startsWith(final String source,
            final String prefix) {
        return prefix.length() <= source.length()
                && source
                        .regionMatches(true, 0, prefix, 0, prefix.length());
    }
}

Related

  1. startsWith(final Object[] left, final Object[] right, final boolean equals)
  2. startsWith(final String fullMethodName, final String prefix)
  3. startsWith(final String s, final String prefix, final boolean ignoreCase)
  4. startsWith(final String s, final String[] prefixes)
  5. startsWith(final String searchString, final String crit)
  6. startsWith(final String src, final String sub)
  7. startsWith(final String str, final char prefix)
  8. startsWith(final String str, final String... prefixes)
  9. startsWith(String baseString, String compareString)