-1

I hope to write a function to return if a string match last char in a string?

For example,

s2 match last chars in a string s1, so the function return true
s3 match last chars in a string s1, so the function return true
s4 match last chars in a string s1, so the function return true
n1 don't match last chars in a string s1, so the function return false
n2 don't match last chars in a string s1, so the function return false
n3 don't match last chars in a string s1, so the function return false
n4 don't match last chars in a string s1, so the function return false

String s1="abcdefg"
String s2="fg"
String s3="efg"
String s4="defg"
String n1="gf"
String n2="ag"
String n3="feg"
String n4="fgg"

4

2 に答える 2

3
public boolean isLastCharEqual(String first, String second) {
    if (first == null || second == null || first.length() == 0 || second.length() == 0) {
        return false;
    }
    return first.contains(second) && (first.charAt(first.length() - 1) == second.charAt(second.length() - 1));
}
于 2013-11-06T03:08:42.880 に答える