1.++i与i++问题
public class Test {
public static int test(){
int i = 0;
try {
i++;
i = i/0;
return i++;
}catch (Exception e){
i++;
return i++;
}finally {
return ++i;
}
}
public static void main(String[] args) {
System.out.println(test());
}
}
结果:4
因为return i++;其实是不会加1的,然而catch中的return语句不会执行的,会进入finally中执行return
2.java 8 stream流的使用
3.算法:双向链表的增加和删除
4.算法:开根号,但是要保留6位小数(不能借助库函数)
5.sql语句中联表查,但是条件是where t2.city = xxx 和 where用and代替的区别
6.String 传参问题
package test;
public class StringTest
{
public static void test(String word){
word = "hey";
System.out.println(word + " boy!");
}
public static void main(String[] args) {
String str = "hello";
test(str);
System.out.println(str);
}
}
输出结果:
hey boy!
hello
String 当入参
首先要明白String对象的内容不可改变。
在main方法中的str是一个引用,str保存了一个内存地址,这个内存地址指向了“hello”这个String对象
test(str)中把这个内存地址赋值给了这个方法中的变量,word
并不是将hello修改为hey,
而是将内存地址复制了一份给word,但是后面word 这个变量改为了hey,这时候会在常量池中新创建一份。
但是实际word怎么变跟外层方法无关,因为是把引用赋值给了局部变量,后面Str创建新的字符串不会在原有的覆盖,
而是新生成一份。