CharBuffer starts With - Java java.nio

Java examples for java.nio:CharBuffer

Description

CharBuffer starts With

Demo Code


//package com.java2s;
import java.nio.CharBuffer;

public class Main {
    public static boolean startsWith(int pos, CharBuffer buf,
            char[] targetChars) {
        int remaining = buf.limit() - pos;

        if (targetChars.length > remaining) {
            return false;
        }//from w w  w.  ja  va 2 s .  co m

        for (int i = 0; i < targetChars.length; i++) {
            if (targetChars[i] != buf.get(i + pos)) {
                return false;
            }
        }

        return true;
    }
}

Related Tutorials