Java String Starts Wtih startsWith(String s, int offset, int end, String t)

Here you can find the source of startsWith(String s, int offset, int end, String t)

Description

True iff s[off:end] starts with t.

License

Apache License

Declaration

static boolean startsWith(String s, int offset, int end, String t) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    /** True iff s[off:end] starts with t. */
    static boolean startsWith(String s, int offset, int end, String t) {
        int n = t.length();
        if (end - offset < n) {
            return false;
        }//w w w .  j a  v a2 s .  com
        int off = offset;
        for (int i = 0; i < n; ++off, ++i) {
            if (s.charAt(off) != t.charAt(i)) {
                return false;
            }
        }
        return true;
    }

    /** True iff s[off:end] starts with t. */
    static boolean startsWith(char[] s, int offset, int end, String t) {
        int n = t.length();
        if (end - offset < n) {
            return false;
        }
        int off = offset;
        for (int i = 0; i < n; ++off, ++i) {
            if (s[off] != t.charAt(i)) {
                return false;
            }
        }
        return true;
    }

    static char charAt(char[] s, int i) {
        return s[i];
    }
}

Related

  1. startsWith(String prefix, String string, boolean caseInsensitive)
  2. startsWith(String receiver, String... needles)
  3. startsWith(String s, boolean caseIgnore, String... args)
  4. startsWith(String s, char begin)
  5. startsWith(String s, char c)
  6. startsWith(String s, String begin)
  7. startswith(String s, String prefix)
  8. startsWith(String s, String prefix)
  9. startsWith(String s, String prefix)