for循环里面不要进行remove操作,for循环里remove元素后,list的下标会减小,导致遍历不完全...

1,不要在 foreach 循环里进行元素的 remove/add 操作

remove 元素请使用 Iterator方式,如果并发操作,需要对 Iterator 对象加锁。

正例:

Iterator<String> iterator = list.iterator(); 
while (iterator.hasNext()) { String item = iterator.next();
if (删除元素的条件) { iterator.remove(); } }

反例:

public static void main(String args[]){
        List<String> list = new ArrayList<String>();
        list.add("1");
        list.add("1");
        for (String item : list) {
            if ("1".equals(item)) { list.remove(item);
        } }
        System.out.println(list.toString());
    }
//output: [1]

for循环里remove元素后,list的下标会减小,导致遍历不完全。

2,asList 的返回对象是一个 Arrays 内部类,并没有实现集合的修改方法。Arrays.asList 体现的是适配器模式,只是转换接口,后台的数据仍是数组。

String[] str = new String[] { "you", "wu" };
List list = Arrays.asList(str);
str[0] = "yy";
System.out.println(list.toString());
//output: [yy, wu]
list.add("yangguanbao"); 
//运行时异常

3,集合类型转换为数组, 要防止数组下标越界的问题。用以下方式转化

List<String> list = new ArrayList<String>(2); 
list.add("guan");
list.add("bao");
String[] array = new String[list.size()];  

4, try{} catch{}语句块中:

 

finally的代码块一定会被执行,即使finally代码块之前函数有return语句,finally代码块也会执行

除以下一种特例: System.exit(0);这条语句后的finally将不再执行

finally的作用是无论是否有异常发生,都要对资源进行释放;资源释放在finally里面

5,同一个类的每个对象有不同成员变量存储空间

同一个类的每个对象共享方法

 

6,java比较对象时,“==”比较的是对象在内存堆内的地址

String重写了Object的equals方法,因而两个相同的字符串,equal返回是true

public boolean equals(Object anObject)

Compares this string to the specified object. 

The result is true if and only if the argument is not null and is a String object 

that represents the same sequence of characters as this object.

 

5,instanceof 判断前面那个类是否属于后面的那个类保护后面列的子类

 

6,LIst,Set,Map集合不能添加基本数据类型(放基本类型能自动装箱成引用类型),必须装object

 

7,  enctype="multipart/form-data"

 form表单在提交图片的文件时要设定enctype类型

不然会报

org.springframework.web.multipart.MultipartException: The current request is not a multipart request

at org.springframework.web.method.annotation.RequestParamMethodArgumentResolver.assertIsMulti

转载于:https://www.cnblogs.com/yanyuechao/p/8371192.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值