请问在hashmap在进行扩容时,是否会对已存储的元素重新计算在数组中的位置?因为元素在数组中的位置=(数组长度-1)&hash;那数组长度变了,已存储的元素存储位置是否也需要改变?
老师,这结课里的hash(key)的方法,为什么通过把这个key的哈希值的前16位与后16位进行异或,就能让数在HashMap的数组中分布均匀啊?
老师这里为啥不用Thread thread=new Thread(new DrawThread())呢
老师我已经自己解决了,不用麻烦了
为什么客户端不直接使用服务器端定义的线程而要重新定义呢
老师为什么我调用不了呀
package com.itbaizhan; import java.util.Arrays;//自定义一个简单的包装类,仅限于练习 public class MyInteger { private final int value; private static MyInteger[]cache;//缓存【-128,127】之间的数字 private static final int LOW=-128; private static final int HIGH=127; static { cache=new MyInteger[HIGH-LOW+1]; for(int i=LOW;i<HIGH;i++){ cache[i-LOW]=new MyInteger(i); } System.out.println(Arrays.toString(cache)); } public MyInteger(int value){ this.value=value; } @Override public String toString() { return value+""; } public static MyInteger valueof(int value){ if(value>=LOW&&value<=HIGH){ return cache[value-LOW]; } return new MyInteger(value);} public static void main(String[] args) { MyInteger a=new MyInteger(10); MyInteger b= new MyInteger(100); MyInteger b2= new MyInteger(100); MyInteger b3 = new MyInteger(1000); MyInteger b4 = new MyInteger(1000); System.out.println(b==b2); System.out.println(b3==b4); int c=b.intvalue(); } public int intvalue(){ return value; } }
不清楚为什么会输出两个false
老师这是什么问题
请问通过哪个快捷键可以直接返回啊
package com.itbaizhan; class manTou{ private int id; public void setId(int id) { this.id = id; } public int getId() { return id; } } //定义缓冲区 不是线程类 class SyncStack{ //定义放馒头的容器 private manTou m[] = new manTou[10]; //索引 int i; //放馒头 public synchronized void push(manTou mantou){ //判断是否满了 while(i == m.length) { //用while多判断几次防止当前线程没有执行而忽略 try { this.wait(); //object类的方法,必须在syn调用,线程的对象锁解放,并且进入堵塞状态 } catch (InterruptedException e) { e.printStackTrace(); } } this.notify(); //唤醒等待序列中的一个线程 this.m[i] = mantou; i++; } //取馒头 public synchronized manTou pop() { //判断是否满了 while (i == 0) { //用while多判断几次防止当前线程没有执行而忽略 try { this.wait(); //object类的方法,必须在syn调用,线程的对象锁解放,并且进入堵塞状态 } catch (InterruptedException e) { e.printStackTrace(); } } this.notify(); //唤醒等待序列中的一个线程 i--; return m[i]; } } //定义生产者线程 class shengchan extends Thread{ private SyncStack s; public shengchan(SyncStack s) { this.s = s; } @Override public void run() { for(int i = 0; i<10; i++){ System.out.println("生产馒头" + i); manTou m = new manTou(); // 每次循环都创建一个新的馒头并放入stack里 s.push(m); } } } class xiaofei extends Thread{ private SyncStack s; public xiaofei(SyncStack s) { this.s = s; } @Override public void run() { for(int i = 0; i < 10; i++){ System.out.println("取馒头" + i); manTou m = s.pop(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } } public class ProducerThread { public static void main(String[] args) { //创建缓冲区 SyncStack s = new SyncStack(); //创建生产线程 shengchan produce = new shengchan(s); produce.start(); //创建消费线程 xiaofei consumer = new xiaofei(s); consumer.start(); } }
QQ图片20230207232704.png
这里两个线程锁的都是同一个对象,那按理说应该等生产线程执行完再执行消费啊,为什么还是并发执行的?
为什么还要声明return?
老师 ,麻烦帮我看一下为什么我的getName标红
它提示我: 无法从static上下文l用非static方法'getName(T)'
请问这一步是什么意思啊
这两者区别有什么不同吗?为啥一个会报错另一个不会
package actualPractice.Practices.TestIO; import java.io.FileInputStream; import java.io.IOException; /** * IO经典流方法 */ public class TestIO { public static void main(String[] args) { FileInputStream fis=null; try { fis=new FileInputStream("d:/a.txt"); StringBuilder sb = new StringBuilder(); int temp=0; //当temp=-1时,表示已经到了文件结尾,停止读取 while((temp=fis.read()) !=-1){ sb.append((char) temp); } System.out.println(sb); } catch (IOException e) { throw new RuntimeException(e); }finally{ //这种写法,保证了即使遇到异常情况,也会关闭对象 if(fis!=null){ try { fis.close(); } catch (IOException e) { throw new RuntimeException(e); } } } } }
老师,文件里everyday后面是感叹号!,请问运行后显示的为什么是这样的?怎么改过来?
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637