Java Char Array Compare charArrayCMP(char[] src, char[] des)

Here you can find the source of charArrayCMP(char[] src, char[] des)

Description

char Array CMP

License

Apache License

Parameter

Parameter Description
src a parameter
des a parameter

Declaration

public static boolean charArrayCMP(char[] src, char[] des) 

Method Source Code

//package com.java2s;

public class Main {
    /**//  ww  w  .  j ava2s  . c  o  m
     * 
     * @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;
    }
}

Related

  1. compareTo(char[] chars1, char[] chars2)