Why String.endsWith and String.startWith are not consistent?

Viewed 630

I have the below test case and only the first assertion passes. Why?

@Test
public void test() {
    String i1 = "i";
    String i2 = "İ".toLowerCase();

    System.out.println((int)i1.charAt(0)); // 105
    System.out.println((int)i2.charAt(0)); // 105

    assertTrue(i2.startsWith(i1));

    assertTrue(i2.endsWith(i1));
    assertTrue(i1.endsWith(i2));
    assertTrue(i1.startsWith(i2));
}

Update after replies

What I am trying to is using startsWith and endsWith in a case insensitive way such that, below expression should return true.

"ALİ".toLowerCase().endsWith("i");

I guess it is different for C# and Java.

4 Answers
Related