Java Char Array Compare compareTo(char[] chars1, char[] chars2)

Here you can find the source of compareTo(char[] chars1, char[] chars2)

Description

compare To

License

Open Source License

Declaration

public static int compareTo(char[] chars1, char[] chars2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.List;

public class Main {
    public static int compareTo(byte b1, byte b2) {
        if (b1 < b2)
            return -1;
        if (b1 > b2)
            return 1;
        return 0;
    }//from   ww w .  j  a va2 s  .  c  om

    public static int compareTo(char c1, char c2) {
        if (c1 < c2)
            return -1;
        if (c1 > c2)
            return 1;
        return 0;
    }

    public static int compareTo(double d1, double d2) {
        if (d1 < d2)
            return -1;
        if (d1 > d2)
            return 1;
        return 0;
    }

    public static int compareTo(float f1, float f2) {
        if (f1 < f2)
            return -1;
        if (f1 > f2)
            return 1;
        return 0;
    }

    public static int compareTo(int i1, int i2) {
        if (i1 < i2)
            return -1;
        if (i1 > i2)
            return 1;
        return 0;
    }

    public static int compareTo(long l1, long l2) {
        if (l1 < l2)
            return -1;
        if (l1 > l2)
            return 1;
        return 0;
    }

    public static <T extends Comparable<T>> int compareTo(T o1, T o2) {
        return o1.compareTo(o2);
    }

    public static <T extends Comparable<T>> int compareTo(List<T> list1,
            List<T> list2) {
        int r = compareTo(list1.size(), list2.size());
        if (r != 0) {
            return r;
        }

        for (int i = 0; i < list1.size(); i++) {
            r = list1.get(i).compareTo(list2.get(i));
            if (r != 0) {
                return r;
            }
        }
        return 0;
    }

    public static int compareTo(short s1, short s2) {
        if (s1 < s2)
            return -1;
        if (s1 > s2)
            return 1;
        return 0;
    }

    public static int compareTo(boolean b1, boolean b2) {
        return (b1 == b2) ? 0 : (b1 ? 1 : -1);
    }

    public static int compareTo(byte[] bytes1, byte[] bytes2) {
        int r = compareTo(bytes1.length, bytes2.length);
        if (r != 0) {
            return r;
        }

        for (int i = 0; i < bytes1.length; i++) {
            r = compareTo(bytes1[i], bytes2[i]);
            if (r != 0) {
                return r;
            }
        }
        return 0;
    }

    public static int compareTo(char[] chars1, char[] chars2) {
        int r = compareTo(chars1.length, chars2.length);
        if (r != 0) {
            return r;
        }

        for (int i = 0; i < chars1.length; i++) {
            r = compareTo(chars1[i], chars2[i]);
            if (r != 0) {
                return r;
            }
        }
        return 0;
    }

    public static int compareTo(double[] doubles1, double[] doubles2) {
        int r = compareTo(doubles1.length, doubles2.length);
        if (r != 0) {
            return r;
        }

        for (int i = 0; i < doubles1.length; i++) {
            r = compareTo(doubles1[i], doubles2[i]);
            if (r != 0) {
                return r;
            }
        }
        return 0;
    }

    public static int compareTo(float[] floats1, float[] floats2) {
        int r = compareTo(floats1.length, floats2.length);
        if (r != 0) {
            return r;
        }

        for (int i = 0; i < floats1.length; i++) {
            r = compareTo(floats1[i], floats2[i]);
            if (r != 0) {
                return r;
            }
        }
        return 0;
    }

    public static int compareTo(int[] ints1, int[] ints2) {
        int r = compareTo(ints1.length, ints2.length);
        if (r != 0) {
            return r;
        }

        for (int i = 0; i < ints1.length; i++) {
            r = compareTo(ints1[i], ints2[i]);
            if (r != 0) {
                return r;
            }
        }
        return 0;
    }

    public static int compareTo(long[] longs1, long[] longs2) {
        int r = compareTo(longs1.length, longs2.length);
        if (r != 0) {
            return r;
        }

        for (int i = 0; i < longs1.length; i++) {
            r = compareTo(longs1[i], longs2[i]);
            if (r != 0) {
                return r;
            }
        }
        return 0;
    }

    public static <T extends Comparable<T>> int compareTo(T[] array1,
            T[] array2) {
        int r = compareTo(array1.length, array2.length);
        if (r != 0) {
            return r;
        }

        for (int i = 0; i < array1.length; i++) {
            r = compareTo(array1[i], array2[i]);
            if (r != 0) {
                return r;
            }
        }
        return 0;
    }

    public static int compareTo(short[] shorts1, short[] shorts2) {
        int r = compareTo(shorts1.length, shorts2.length);
        if (r != 0) {
            return r;
        }

        for (int i = 0; i < shorts1.length; i++) {
            r = compareTo(shorts1[i], shorts2[i]);
            if (r != 0) {
                return r;
            }
        }
        return 0;
    }

    public static int compareTo(boolean[] booleans1, boolean[] booleans2) {
        int r = compareTo(booleans1.length, booleans2.length);
        if (r != 0) {
            return r;
        }

        for (int i = 0; i < booleans1.length; i++) {
            r = compareTo(booleans1[i], booleans2[i]);
            if (r != 0) {
                return r;
            }
        }
        return 0;
    }
}

Related

  1. charArrayCMP(char[] src, char[] des)