相关疑难解决方法(0)

如何比较Java中的字符串?

==到目前为止,我一直在我的程序中使用运算符来比较我的所有字符串.但是,我遇到了一个错误,将其中一个更改为了.equals(),并修复了该错误.

==坏?什么时候应该不应该使用它?有什么不同?

java string equality

726
推荐指数
23
解决办法
376万
查看次数

Commons Lang StringUtils.replace性能vs.String.replace

当我比较Apache的性能StringUtils.replace()VS String.replace()我很惊讶地知道,前者是快约4倍.我使用Google的Caliper框架来衡量效果.这是我的考试

public class Performance extends SimpleBenchmark {
    String s = "111222111222";

    public int timeM1(int n) {
        int res = 0;
        for (int x = 0; x < n; x++) {
            res += s.replace("111", "333").length();
        }
        return res;
    }

    public int timeM2(int n) {
        int res = 0;
        for (int x = 0; x < n; x++) {
            res += StringUtils.replace(s, "111", "333", -1).length();
        }
        return res;
    }

    public static void main(String... args) {
        Runner.main(Performance.class, args);
    } …
Run Code Online (Sandbox Code Playgroud)

java

39
推荐指数
4
解决办法
4万
查看次数

标签 统计

java ×2

equality ×1

string ×1