多线程
run方法是用来描述多线程任务内容的.
start方法才是用来开启多线程任务的.
接口
实现类中实现接口的时候,方法的名字,返回值类型,参数的个数及类型必须与接口中的安全一致,并且必须实现接口中的方法.
接口实现类相当于子类,子类的访问权限是不能比父类小.
接口中的方法默认 是public,所以他的实现类访问修饰符是不能比父类小的.
变量是用 public static final 修饰的,但是可以省略
赋值
基本类型是可以进行自动类型转换的
A选项是 八进制整形
B选项是 整形自动转为单精度浮点数
C选项是 boolean类型不能进行类型转换
D选项是 十六进制整数转为 双精度浮点数
E选项是 byte类型范围为-128 - 127;
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-IGAA4Hzk-1638078645121)(C:\Users\精神小伙\AppData\Roaming\Typora\typora-user-images\image-20211112223710323.png)]
flush作用()
字符输出流中大多的方法使用了缓冲区,
当读取的文件小于缓冲区大小的时候,此时不会自动进行输出,必须大于缓冲区或者使用flush()方法才会进行一次写入
调用close方法的时候也会调用一次flush方法
评论区的速记:
喂 she !线程安全! 喂(vector),s(stack)h(hashtable)e(enumeration)
vector 线程安全,效率低
剑指 Offer 15. 二进制中1的个数 - 力扣(LeetCode) (leetcode-cn.com)
public class Solution {
// you need to treat n as an unsigned value
public int hammingWeight(int n) {
int total = 0;
while(n!=0){
if((n&1)==1){
total++;
}
n = n>>>1;
}
return total;
}
}
剑指 Offer 18. 删除链表的节点 - 力扣(LeetCode) (leetcode-cn.com)
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; }
* }
*/
class Solution {
public ListNode deleteNode(ListNode head, int val) {
//定义一个假头
ListNode fakehead = new ListNode(0);
//链接假头
fakehead.next = head;
//组成快慢指针
ListNode tail = head;
head = fakehead;
while(head!=null){
if(tail.val == val){
head.next = tail.next;
tail = null;//内存便于回收
break;
}
tail = tail.next;
head = head.next;
}
return fakehead.next;
}
}