小编use*_*526的帖子

如果使用String实现String连接是使用StringBuilder实现的,那么为什么在连接期间会创建额外的对象?

如果以下代码:

String s = "a" + 1 + "b";// 1.
Run Code Online (Sandbox Code Playgroud)

使用StringBuilder等效实现

String s = new StringBuilder().append("a").append(1).append("b");
Run Code Online (Sandbox Code Playgroud)

然后将在1中创建额外的对象"a"和"b",为什么?

java string stringbuilder

7
推荐指数
2
解决办法
537
查看次数

如何使用adobe photoshop识别png图像中的font-family

我有一个png图像,文字我无法识别,有没有办法可能通过adobe photoshop或任何其他方法识别图像上的字体系列.

fonts image image-recognition

7
推荐指数
2
解决办法
7万
查看次数

为什么这个instanceof代码工作并且不会导致编译时错误?

在下面的代码中,x的类型是I(虽然x也实现了J但在编译时不知道),为什么(1)处的代码不会导致编译时错误.因为在编译时只考虑引用的类型.

public class MyClass {
    public static void main(String[] args) {
        I x = new D();
        if (x instanceof J) //(1)
            System.out.println("J");
    }
}

interface I {}

interface J {}

class C implements I {}

class D extends C implements J {}
Run Code Online (Sandbox Code Playgroud)

java instanceof

6
推荐指数
1
解决办法
4059
查看次数

为什么"A"或没有输出只能输出此代码,它也可能是"AB"?

根据我所读到的,该程序唯一可能的输出是"A"打印输出还是没打印输出.但是由于语句new MyString("A").concat("B");是用字符串创建一个新对象,"AB"这个对象也不能被垃圾收集导致输出"AB"吗?

class MyString { 

    private String str;
    MyString(String str) { this.str = str; }
    public void finalize() throws Throwable {
        System.out.print(str);
        super.finalize();
    }
    public void concat(String str2) {
        this.str.concat(str2);
    }
    public static void main(String[] args) {
        new MyString("A").concat("B");
        System.gc();
    }
}
Run Code Online (Sandbox Code Playgroud)

java garbage-collection

2
推荐指数
1
解决办法
90
查看次数

如何在两天内学习专业JavaScript?

我真的需要在两天内学习专业的javascript,因为我必须立即开始(现实世界项目).我几乎没有什么可以近似于没有JavaScript或网站开发的知识.任何帮助将非常感激.

javascript web

2
推荐指数
1
解决办法
1万
查看次数

当与输入匹配时包含锚($)的正则表达式在以下程序中显示意外结果,为什么?

/*
    patString: it$
    input: this is it
    the output at 2 to the match operation at 1 is false, why?
*/

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.Console;

public class Test {
    public static void main(String args[])  {
        Console con = System.console();
        String patString, input;
        patternString  = con.readLine("Enter pattern: "); //pattern 
        input =  con.readLine("input: "); // input string to match against pattern
        Pattern pattern = Pattern.compile(patString);
        Matcher matcher = pattern.matcher(input);
        boolean testMatch = matcher.matches(); //1
        System.out.println("match found: " + testMatch); //2 …
Run Code Online (Sandbox Code Playgroud)

java regex

1
推荐指数
1
解决办法
140
查看次数

这个计划发生了什么,更重要的是,为什么?

请帮助我理解这个程序的执行情况以及更广泛意义上适用的概念?解释线程/堆栈创建和销毁的说明将是有帮助的.

class Joining {

    static Thread createThread(final int i, final Thread t1) {
        Thread t2 = new Thread() {
            public void run() {
                System.out.println(i+1);
                try {
                    t1.join(); 
                } catch (InterruptedException ie) {
                }
                System.out.println(i+2);
            }
        };
        System.out.println(i+3);
        t2.start(); //1
        System.out.println(i+4);
        return t2;
    }
    public static void main(String[] args) {
        createThread(10, createThread(20, Thread.currentThread()));
    }
}
Run Code Online (Sandbox Code Playgroud)

java concurrency multithreading

0
推荐指数
1
解决办法
162
查看次数