Write code to check if a string starts With another string ignore case
//package com.book2s; public class Main { public static void main(String[] argv) { String text = "book2s.com"; String fragment = "book2s.com"; System.out.println(startsWith(text, fragment)); }/*w ww .j a va2 s . c om*/ public static boolean startsWith(final String text, final String fragment) { return startsWithIgnoreCase(text, fragment); } public static boolean startsWithIgnoreCase(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(0, target2.length()); return s1.equalsIgnoreCase(target2); } public static boolean equalsIgnoreCase(final String target1, final String target2) { return (target1 == null) ? (target2 == null) : target1 .equalsIgnoreCase(target2); } }