Collection接口为什么没有get()方法? Collection这个接口只能用子类实例化,又没有get()方法(子接口List中才有)。实例化了,添加了元素我怎么取出来呢,比如:Collection<String> col=new ArrayList<String>()取个元素,更改个元素好麻烦。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Collection<String> col=new ArrayList<String>()for(String str : col.iterator()){ //} 因为Set不需要get方法,所以不能从List提升到Collection 迭代是个不错方法,但如果我想像List一样取出(更改)指定索引位置的元素,怎么办呢?必须用List么?为什么Set不需要?我向里面添加了数据,我都想方便的从里面取出来(或更改某一索引位置的元素,像数组一样) 为了满足这样的需求,我弄了个String的数组,把里面的元素一个一个放进去,改完了,又把数组转成List再换给他,麻烦。有什么简便方法么?public void update(int x,String t) { String[] s=new String[this.getColl().size()]; Iterator<String> it=this.getColl().iterator(); while(it.hasNext()) { for(int i=0;i<s.length;i++) { s[i]=it.next(); } } s[x]=t; this.cle=Arrays.asList(s); } 那你直接List<String> col=new ArrayList<String>();不就得了 是,直接用List早就不用纠结了,我就没想明白,为什么非得这样设计。 如果你认为这个this.getColl()应该存在get方法,那说明它应该是一个List sessionFactory is not writable 异常 这段代码是什么意思? 用java怎么将word文档转成图片格式 “实现接口的类要实现接口的所有方法,否则应该将该类声明为abstract” hql 是否支持 order by nulls first / last ?? 我的输入这块 什么问题呀?请赐教! 如何将 2,8,16 进制转换为10进制? 关闭副窗口,却把主窗口也关闭了??? N处错误咋改呀 为啥我的汉字得不到unicode码?!!! synchronized同步问题 求一个匹配字符串的算法
for(String str : col.iterator()){
//
}
{
String[] s=new String[this.getColl().size()];
Iterator<String> it=this.getColl().iterator();
while(it.hasNext())
{
for(int i=0;i<s.length;i++)
{
s[i]=it.next();
}
}
s[x]=t;
this.cle=Arrays.asList(s);
}
不就得了
是,直接用List早就不用纠结了,我就没想明白,为什么非得这样设计。