Is the character at index 'pos' of CharBuffer one of the characters in the 'candidate Characters' array? - Java java.nio

Java examples for java.nio:CharBuffer

Description

Is the character at index 'pos' of CharBuffer one of the characters in the 'candidate Characters' array?

Demo Code


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

public class Main {
    /**//from   w ww  . j  ava 2 s.  c  om
     * Is the character at index 'pos' of 'buf' one of the characters in the
     * 'candidateCharacters' array?
     */
    public static boolean isOneOf(int pos, CharBuffer buf,
            char[] candidateCharacters) {
        char c = buf.get(pos);

        for (int i = 0; i < candidateCharacters.length; i++) {
            if (candidateCharacters[i] == c) {
                return true;
            }
        }

        return false;
    }
}

Related Tutorials