Java String Starts Wtih startsWith(T[] arr, T[] prefix)

Here you can find the source of startsWith(T[] arr, T[] prefix)

Description

Tests if the array starts with another prefix array.

License

Open Source License

Parameter

Parameter Description
arr array to check prefix in
prefix prefix array
T type of array elements

Return

true if array starts with prefix, false otherwise

Declaration

public static <T> boolean startsWith(T[] arr, T[] prefix) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from w ww .  j  a  v  a 2  s. c o  m
     * Tests if the array starts with another prefix array.
     * @param arr array to check prefix in
     * @param prefix prefix array
     * @param <T> type of array elements
     * @return {@code true} if array starts with prefix, {@code false} otherwise
     */
    public static <T> boolean startsWith(T[] arr, T[] prefix) {
        if (arr.length < prefix.length)
            return false;

        for (int i = 0; i < prefix.length; i++) {
            if (!arr[i].equals(prefix[i]))
                return false;
        }

        return true;
    }
}

Related

  1. startsWith(String[] searchStrings, String text)
  2. startsWith(String[] target, String[] with)
  3. startsWith(StringBuffer buffer, String prefix)
  4. startsWith(StringBuilder builder, String prefix, int offset)
  5. startsWith(StringBuilder sb, String prefix)
  6. startsWith4(String string, int startIndex, int char1, int char2, int char3, int char4)
  7. startsWithAcronym(String word)
  8. startsWithAndHasMore(String input, String toStartWith)
  9. startsWithAny(String _str, String... _startStrings)