标签:java io 数据 for ar 问题 cti 工作
今天跟朋友讨论一个小的知识点,发现很多人不知道collection接口中定义的add方法是有返回值的,大家都是工作很多年的Java从业人员了,对公用接口的不熟悉会让自己在细节上吃亏的。这让我想到了刚入行的时候的一个小面试,另外一个项目的项目经理神秘兮兮的问,jdbc调用sql执行完成之后,返回什么值?下面是一个小例子,细节决定成败,与君共勉。
import java.util.Collection;
import java.util.HashSet;
public class CollectionInterface {
public static void main(String[] args) {
int[] arrays = new int[]{1,2,3,4,5,6,7,8,9,10,1,2,3,4,5};
Collection<Integer> set = new HashSet<Integer>();
int counter = 0;
for(int temp :arrays){
if(set.add(temp)){
counter++;
}else{
System.out.println("The date "+temp+" has already been existent,discard it.");
}
}
System.out.println("counter=> "+counter);
System.out.println("set.size()=> "+set.size());
}
}
CoreJava_Collection接口中的add是有返回值的!,布布扣,bubuko.com
CoreJava_Collection接口中的add是有返回值的!
标签:java io 数据 for ar 问题 cti 工作
原文地址:http://blog.csdn.net/ziwen00/article/details/38660125