Java String Starts Wtih startsWithOrMatches(String s1, String s2)

Here you can find the source of startsWithOrMatches(String s1, String s2)

Description

Combination of startsWith and matches string comparison.

License

Open Source License

Declaration

public static boolean startsWithOrMatches(String s1, String s2) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from w ww. j  a v a2  s  . c o m*/
     * Combination of startsWith and matches string comparison. StartsWith has the higher priority. Null checking is
     * also included. If both parameters are null, the returned value is true.
     */
    public static boolean startsWithOrMatches(String s1, String s2) {
        if (s1 == null) {
            return s2 == null;
        }

        if (s2 == null) {
            return false;
        }

        return s1.startsWith(s2) || s1.matches(s2);
    }
}

Related

  1. startsWithNoCase(String csValue, String csStart)
  2. startsWithOne(final String src, final String[] dest)
  3. startsWithOneOf(String source, boolean ignoreCase, String... values)
  4. startsWithOneOf(String str, String... strs)
  5. startsWithOneOf(String string, String... prefixes)
  6. startsWithPattern(String value, String matchingPatterns)
  7. startsWithPhraseSeparator(char[] token)
  8. startsWithPrefix(final String methodName, final String prefix, final int prefixLength)
  9. startsWithPrefix(String inputText, String[] prefixes)