首页
\
问答
\
什么是线程启动方法的需要?(What is the need of Thread start method? why not have only run method? [duplicate])
什么是线程启动方法的需要?(What is the need of Thread start method? why not have only run method? [duplicate])
这个问题在这里已经有了答案:
通过启动方法运行线程需要什么? 我们为什么不直接调用方法?
What will happened if combined the code of start() and run() to make it as single method run()
不要解释两种方法之间的区别,我想知道这种情况。
This question already has an answer here:
What is the need to run the thread through start method? Why not we call directly run method ?
What will happened if combined the code of start() and run() to make it as single method run()
Dont explain the difference between both method, i want to know about this scenario.
原文:https://stackoverflow.com/questions/24843040
更新时间:2022-08-16 16:08
最满意答案
您应该将您的字符串变量与
.equals()
方法而不是==
运算符进行比较。关于为什么这很重要的解释可以在StackOverflow上找到。
You should compare your String variables with the
.equals()
method instead of the==
operator.An explanation about why this is important can be found here on StackOverflow.
相关问答
更多-
使用break : while (true) { .... if (obj == null) { break; } .... } 但是,如果您的代码看起来和您指定的一样,可以使用正常的while循环,并将条件更改为obj != null : while (obj != null) { .... } Use break: while (true) { .... if (obj == null) { break; ...
-
nextInt()不会抓取行尾字符,也不会在输入数字后输入“enter”。 相反,您可以使用nextLine()并获取整行,然后像这样将其解析为Integer int players = Integer.parseInt(reader.nextLine()); The nextInt() doesn't grab the end of line character, AKA the "enter" after the number is entered. Instead you can use nextL ...
-
您应该将您的字符串变量与.equals()方法而不是==运算符进行比较。 关于为什么这很重要的解释可以在StackOverflow上找到。 You should compare your String variables with the .equals() method instead of the == operator. An explanation about why this is important can be found here on StackOverflow.
-
以下将连接相同类型的数组: String[] both = ArrayUtils.addAll(first, second); 它类似于这样的东西: ArrayUtils.addAll(["a", "b", "c"], ["1", "2", "3"]) = ["a", "b", "c", "1", "2", "3"] 更多详情: doc链接 有多种方法可以高效地连接java数组,请检查此stackoverflow帖子以找到最佳示例: stackoverflow后链接 The following will ...
-
一如既往的性能:编写最简单的代码,并测试它,看它是否表现良好。 如果你只需要元素(而不是索引),我会鼓励你使用增强的for循环: for (int value : array) { ... } 根据JLS 14.14.2 ,这基本上等同于您的第一段代码,但代码只会谈论您实际感兴趣的内容。 但是,如果您确实需要索引,并且假设您不在任何地方更改array ,我相信JIT编译器将优化本机代码以仅获取一次。 获取长度是一个O(1)操作,因为它基本上只是数组中的一个字段,但显然它确实涉及到了内存,所以最好的 ...
-
根据forEach的MDN Javascript文档: 除了抛出异常之外,没有办法停止或中断forEach()循环。 参考: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach According to the MDN web docs: There is no way to stop or break a forEach() loop other than by t ...
-
您应该将字符串与String.equals进行比较 所以你的代码应该是这样的: while (!GuessPass.equals(SetPass)){ 并且如评论中所提到的,我将更改变量的名称以匹配Java标准(camelCase用于局部变量和方法),因此总结: while (!guessPass.equals(setPass)){ You should compare the string with String.equals so your code should look like this : ...
-
我试图在java中退出while循环(同时也使用for循环)(I'm trying to exit while loop (while also using a for loop) in java)[2022-11-06]
我实际上没有测试过这个,但我认为问题是退出for循环。 测试的最快方法就是使用带有标签的break语句。 outerLoop: do // ... else if(selection == 3) { break outerLoop; } }//end of for array loop }while (programSelection == true); ... -
下面是测试类。 请让我知道这可不可以帮你 package com.test; import org.json.JSONArray; import org.json.JSONObject; public class JSONTest { public static void main(String[] args){ JSONArray jsonArray = new JSONArray(); JSONObject j1 = new JSONObject(); j1.put("id", "1"); j1.p ...
-
我最好的猜测:添加一些睡眠条件,让其他线程有时间填充结果。 在你的问题中你说它需要大约5秒钟; 添加busy-wait循环时,这可能需要更长时间(同时为true)。 尝试: while (true) { while (value == 0) { value = utils.getValue(); try { Thread.sleep(500); } catch (InterruptedException e) { ...