I have a funtion in my program that should determine if the last char of a string is a / and if not, add a / at the end, however, it always adds a /, even if the last char is a / Here is the code:
public static String setLastCharSlash(String check) {
if(check.substring(check.length() - 1) != "/") {
check = check + "/";
}
return check;
}
There's a specific method for this use case:
boolean isSlashLast = "your/string/".endsWith("/");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With