如果以下代码:
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",为什么?
我有一个png图像,文字我无法识别,有没有办法可能通过adobe photoshop或任何其他方法识别图像上的字体系列.
在下面的代码中,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) 根据我所读到的,该程序唯一可能的输出是"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) 我真的需要在两天内学习专业的javascript,因为我必须立即开始(现实世界项目).我几乎没有什么可以近似于没有JavaScript或网站开发的知识.任何帮助将非常感激.
/*
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) 请帮助我理解这个程序的执行情况以及更广泛意义上适用的概念?解释线程/堆栈创建和销毁的说明将是有帮助的.
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 ×5
concurrency ×1
fonts ×1
image ×1
instanceof ×1
javascript ×1
regex ×1
string ×1
web ×1