Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {

    public static boolean endWiths(byte[] all, byte[] sub) {
        if (all == null || sub == null || all.length < sub.length)
            return false;
        int allLen = all.length;
        int subLen = sub.length;

        for (int i = 1; i < (subLen + 1); i++) {
            if (all[allLen - i] != sub[subLen - i])
                return false;
        }

        return true;
    }

    public static boolean endWiths(byte[] all, int length, byte[] sub) {
        if (all == null || sub == null || length < sub.length)
            return false;

        int allLen = Math.min(all.length, length);
        int subLen = sub.length;

        for (int i = 1; i < (subLen + 1); i++) {
            if (all[allLen - i] != sub[subLen - i])
                return false;
        }

        return true;
    }
}