java - 简单的java boolean 值。为什么这会返回 false?

标签 java boolean

public class Main {

public static void main(String[] args) {
    System.out.println(endOther("Hiabc","abc"));

}

public static boolean endOther(String a , String b) {

    System.out.println(a.substring(a.length() - b.length()));
    return a.substring(a.length() - b.length()) == b;
}
}

基本上它会打印“abc”,但随后返回 false,我不知道为什么

最佳答案

在Java中不要使用==来比较字符串,使用equals()

关于java - 简单的java boolean 值。为什么这会返回 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55107577/

相关文章:

java - 在 Spring 中使用 RestTemplate 的 MultipartFile + String 作为请求参数

java - LOGGER.info 和 LOGGER.debug 显示为红色,且无法解析方法

java.lang.IllegalArgumentException : No view found for id 0x7f0c0098

c++ - 在 if 语句 C++ 中使用 bool 数组

java - 为什么静态 transient 字段被序列化?

java - 无法在 jsoup 中使用文档

php - 期望参数 1 是 mysqli_result,给定的 boolean 值

Jenkins 管道 boolean 参数评估

sql - 如何对 SQL 选择执行 boolean 加法

ruby 为什么0 || 1 是 0