Java - Write code to check if a string ends With another string Ignore Case

Requirements

Write code to ends With Ignore Case

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String target1 = "book2s.com";
        String target2 = "book2s.com";
        System.out.println(endsWithIgnoreCase(target1, target2));
    }//from ww w .j  ava2  s  . com

    public static boolean endsWithIgnoreCase(final String target1,
            final String target2) {
        if (target1 == null || target2 == null) {
            return false;
        }
        int length1 = target1.length();
        int length2 = target2.length();
        if (length1 < length2) {
            return false;
        }
        String s1 = target1.substring(length1 - length2);
        return s1.equalsIgnoreCase(target2);
    }

    public static boolean equalsIgnoreCase(final String target1,
            final String target2) {
        return (target1 == null) ? (target2 == null) : target1
                .equalsIgnoreCase(target2);
    }
}