回复楼上,@王浩信,老师写错了它口头说的24是对的,12 << 1 肯定就是24啊,只不过它写的时候写错了。因为后面要用到newThr,7:24时老师再次说了newThr为24。
怎么才能执行到异常那一部分
class A implements Runnable{ private Thread b; public A(Thread b){ this.b=b; } @Override public void run() { for (int i=0;i<10;i++){ System.out.println(Thread.currentThread().getName()+" A "+i); if (i==6){ try { b.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } } try { Thread.sleep(1000); } catch (InterruptedException e) { throw new RuntimeException(e); } } } } class B implements Runnable{ @Override public void run() { for (int i =0;i<20;i++){ System.out.println(Thread.currentThread().getName()+" B "+i); try { Thread.sleep(1000); } catch (InterruptedException e) { throw new RuntimeException(e); } } } } public class TestJoinThread{ public static void main(String[] args) { Thread t1 = new Thread(new A(t)); Thread t = new Thread(new B()); t1.start(); t.start(); for (int i=0;i<10;i++){ System.out.println(Thread.currentThread().getName()+" 主线程 "+i); if (i==4){ try { t1.join(); } catch (InterruptedException e) { throw new RuntimeException(e); } } try { Thread.sleep(1000); } catch (InterruptedException e) { throw new RuntimeException(e); } } } }
Thread t1 = new Thread(new A(t)); Thread t = new Thread(new B());
为什么写成这样报错,不都是把B给A里了吗
Thread t1 =
new
Thread(
B());
Thread t =
A(t1));
视频是这样的
还有为什么要先创建线程B的对象
请问老师,不应该在orderName这些方法中遍历一下list嘛,要不然怎么会显示在运行框呢
public void orderName(){ Collections.sort(this.list,new OrderByName()); for (int i = 0; i < this.list.size(); i++) { (this.list.get(i)).setId(i+1); } this.list.forEach(System.out::println); }
package com.itbaizhan; public class Test2 { public static void main(String[] args) { MethodGeneric c=new MethodGeneric(); c.setName("123"); Integer age=c.getage("23"); System.out.println(age); } }
想问一下c.getage()为什么里面加了双引号就会报错为在c.setName()里就没有关系?
想问问老师,在哈希表中,当链表超过8的时候,是把那一整条链表都转化为红黑树还是只把链表超过8的那一部分转化为红黑树呀
package com.renyiyv; import java.io.File; import java.io.IOException; import java.util.Date; //测试文件类 public class TestFile { public static void main(String[] args) throws IOException { System.out.println(System.getProperty("user.dir")); File f=new File("d:/a.txt");//绝对路径 f.createNewFile();//创建新的File File f2=new File("b.txt");//相对路径 f2.createNewFile(); System.out.println("File是否存在:"+f.exists()); System.out.println("File是否是目录:"+f.isDirectory()); System.out.println("File是否是文件:"+f.isFile()); System.out.println("File最后的修改时间:"+new Date(f.lastModified())); System.out.println("File的大小:"+f.length()); System.out.println("File的文件名:"+f.getName()); System.out.println("File的目录路径"+f.getAbsolutePath()); File f3=new File("d:电影/华语/大陆"); //boolean flag=f3.mkdir();//目录结构中有一个不存在,则不会创建整个目录树 //System.out.println(flag);//创建失败 boolean flag=f3.mkdirs(); System.out.println(flag); } }
老师您好,根据代码,f3目录理论上应该在d盘下创建的才对,我这个为什么在项目文件夹里?
import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class ArrayListTest2 { public static void main(String[] args) { //实例化ArrayList容器 List<String> list = new ArrayList<>(); //添加元素 list.add("sxt"); list.add("itbz"); //向指定位置添加元素 list.add(0,"wuhu"); Object[] objects = list.toArray(); System.out.println(Arrays.toString(objects)); System.out.println("获取元素"); String s = list.get(1); System.out.println(s); System.out.println("获取所有元素方式一"); for(int i=0;i< list.size();i++){ System.out.println(list.get(i)); } System.out.println("获取所有元素方式二"); for (String str:list) { System.out.println(str); } System.out.println("元素替换"); String d = list.set(1, "dalao"); System.out.println(d); System.out.println("根据索引位置删除元素"); String remove = list.remove(1); System.out.println(remove); System.out.println("查找容器中元素第一次出现的索引位置"); int sxt = list.indexOf("sxt"); System.out.println(sxt); System.out.println("查找容器中元素最后一次出现的索引位置"); int sxt1 = list.lastIndexOf("wuhu"); System.out.println(sxt1); } }
查找容器中元素第一次出现的索引位置
这里的返回值为-1,前面最开始不是添加过"sxt"了吗?
怎么算是自身有比较规则
public static void main(String[] args) {
18 System.out.println("主线程开始");
19 Thread t = new Thread(new SleepThread());
20 t.start();
21 System.out.println("主线程结束");
22 }
23}
这儿的主线程结束位置是不是放错了
list容器和数组容器的区别是什么,感觉功能除了动态性其他都一样,那为何不用List容器去代替数组存储呢?
接口默认继承object类吗?
单例集合和双例集合不太懂
老师你好,下面有一段是format.format(date2),第一个是追溯到上面那个yyyy那边的格式,那后面的format的作用是什么,是因为语法原因来调用date2才加上去的吗?
数字后面加了个L,是代表毫秒单位吗
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637