Java Char Array Index Of charArrayIndexOf(char[] src, char des, int start)

Here you can find the source of charArrayIndexOf(char[] src, char des, int start)

Description

char Array Index Of

License

Apache License

Parameter

Parameter Description
src a parameter
des a parameter
start a parameter

Declaration

public static int charArrayIndexOf(char[] src, char des, int start) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  w  w w. j a  va  2 s.  co  m
     * 
     * @param src
     * @param des
     * @param start
     * @return
     */
    public static int charArrayIndexOf(char[] src, char des, int start) {
        for (int i = start; i < src.length; i++) {
            if (src[i] == des)
                return i;
        }
        return -1;
    }

    /**
     * 
     * @param src
     * @param des
     * @param start
     * @return
     */
    public static int charArrayIndexOf(char[] src, char[] des, int start) {
        for (int i = start; i < src.length; i++) {
            if (charArrayCMP(src, start, des.length, des, 0, des.length))
                return i;
        }
        return -1;
    }

    /**
     * 
     * @param src
     * @param des
     * @param start
     * @return
     */
    public static int charArrayIndexOf(char[] src, char des, int start, int len) {
        for (int i = start; i < start + len; i++) {
            if (src[i] == des)
                return i;
        }
        return -1;
    }

    /**
     * 
     * @param src
     * @param des
     * @param start
     * @return
     */
    public static int charArrayIndexOf(char[] src, char[] des, int start, int len) {
        for (int i = start; i < start + len; i++) {
            if (charArrayCMP(src, start, des.length, des, 0, des.length))
                return i;
        }
        return -1;
    }

    /**
     * 
     * @param src
     * @param des
     * @return
     */
    public static boolean charArrayCMP(char[] src, char[] des) {
        if (src.length != des.length)
            return false;
        for (int i = src.length - 1; i >= 0; i--) {
            if (src[i] != des[i])
                return false;
        }
        return true;
    }

    /**
     * 
     * @param src
     * @param src_start
     * @param src_len
     * @param des
     * @param des_start
     * @param des_len
     * @return
     */
    public static boolean charArrayCMP(char[] src, int src_start, int src_len, char[] des, int des_start,
            int des_len) {
        if (src_len != des_len)
            return false;
        if (src_start + src_len > src.length)
            return false;
        if (des_start + des_len > des.length)
            return false;
        for (int i = src_len - 1; i >= 0; i--) {
            if (src[src_start + i] != des[des_start + i])
                return false;
        }
        return true;
    }
}