校园网站建设情况说明,宁波微信小程序开发公司,苏州营销型网站,上海开发appList实现类 java.util.ArrayList#xff1a; 底层通过数组保存数据 #xff0c; 查询快#xff0c;增删慢 java.util.LinkedList#xff1a; 底层通过链表保存数据#xff0c; 查询慢#xff0c;增删快 如果对操作性能没有特殊要求#xff0c;我们一般选择ArrayList… List实现类 java.util.ArrayList 底层通过数组保存数据 查询快增删慢 java.util.LinkedList 底层通过链表保存数据 查询慢增删快 如果对操作性能没有特殊要求我们一般选择ArrayList即可同时考虑具体业务 List方法 ListString link new LinkedList();link.add(1); link.get(2); link.set(0,一); Collections.reverse(link); //自动反转 for (int i 0; i link.size() / 2; i) {String tem link.get(i);link.set(i, link.get(link.size()-1-i));link.set(link.size()-1-i,tem);
}
System.out.println(link); //自动反转方法二 ListInteger subList list.subList(3, 8); //截取集合中的子集(含头不含尾) 集合 数组 的转换 集合转换成数组 CollectionString c new ArrayList(); Collection提供了将集合转换成数组的方法 Object[] objects c.toArray(); ArrayList重载了一个toArray方法 String[] sts c.toArray(new String[c.size()]); 数组转换成集合 java.util.Arrays提供了一个静态方法asList,可以将数组转换成集合 String[] arr {one, two, three, four, five, six}; ListString list Arrays.asList(arr); list.set(2,二); //这里会直接报错
System.out.println(list); //打印集合
System.out.println(Arrays.toString(arr)); //打印数组元素
//因为数组是定长的因此该集合的增删元素都会抛出 UnsupportedOperationException异常
//对集合的操作就是对原数组的操作
//操作数组转换的集合 会改变数组本身
还有sublist截取的集合子集进行增删也一样会改变集合 如果必须要增删元素需要自行创建一个新的集合 所有集合都支持一个参数为Collection的构造函数 作用是在创建当前集合的 同时包含指定集合中的所有元素 ListString list2 new ArrayList(list); //创建list2集合的同时包含list集合中的所有元素 集合的排序 java.utils.Collections提供了一个静态方法short() 可以对集合进行自然排序升序从小到大 Collections.sort(list); 自定义排序 Collections.sort(List list) 该方法要求集合元素必须实现接口Comparable,否则编译不通过。 * Comparable接口是用来表示实现类是可以比较大小的 实现类必须重写方法compareTo * compareTo用来定义两个实例比较大小的规则。 * 例如包装类 String类等都实现了这个接口 * * 如果该方法不能直接使用就不建议使用了因为该方法对我们的代码产生了侵入性。 * 侵入性当我们使用某个API时其要求我们为其更改其他地方的代码这就是侵入性。 * 侵入性不利于后期代码维护应当尽力避免。 侵入性也大大提高了代码的耦合度违背了 * 代码“高内聚低耦合”的原则 自定义排序二 //COllections下的sort方法要想使用必须// 在元素中实现comparable接口//comparable接口是用来表示实现类可以比较大小//实现类必须重写方法//compareTo定义比较大下的规则//Collections重载了short方法//sort(List,Comparator)//需要传入一个比较器对象
// ComparatorPoint c new ComparatorPoint() {
// Override
// public int compare(Point o1, Point o2) {
// int m1 o1.getX()*o1.getX() o1.getY()*o1.getY();
// int m2 o2.getX()*o2.getX() o2.getY()*o2.getY();
// return m1-m2;
// }
// };
// Collections.sort(l,c);// Collections.sort(l,
// ( o1, o2) - (o1.getX()*o1.getX() o1.getY()*o1.getY())-(o2.getX()*o2.getX() o2.getY()*o2.getY())
// ); lambda表达式排序集合 ListString list new ArrayList(); list.add(杨玉捷); list.add(博文); list.add(殷桃小丸子); list.add(西门长海); Collections.sort(list,(s1,s2)-s1.length()-s2.length()); 栈内存结构 Stack继承自Vector * 特点 先进后出后进先出 * 入栈/压栈 ----数据进入栈 * 出栈/弹栈-----数据离开栈 * 栈顶元素------最后放入栈中的元素 * 栈底元素------最先放入栈中的元素 Stack s new Stack();
s.push(a);
s.push(b);
s.push(c);
s.push(d);
s.empty(); //是否为空栈
s.pop(); //peek并删除
s.peek(); //获取栈顶元素
System.out.println(s);
s.search(a); //从栈顶往下数 1开始 用双端队列表示栈 Deque d new LinkedList();
d.add(a);
d.add(b);
d.add(c);
d.add(d);d.pop();
d.peek(); Vector VectorString v new Vector(); System.out.println(v);
System.out.println(v.size());
System.out.println( v.capacity());//初始容量 10 三目运算符 自动扩容
EnumerationString elements v.elements();
while (elements.hasMoreElements()){String s elements.nextElement();System.out.println(s);
} 文章转载自: http://www.morning.qzbwmf.cn.gov.cn.qzbwmf.cn http://www.morning.xcdph.cn.gov.cn.xcdph.cn http://www.morning.jxjrm.cn.gov.cn.jxjrm.cn http://www.morning.bylzr.cn.gov.cn.bylzr.cn http://www.morning.cnhgc.cn.gov.cn.cnhgc.cn http://www.morning.nynyj.cn.gov.cn.nynyj.cn http://www.morning.xplng.cn.gov.cn.xplng.cn http://www.morning.splkk.cn.gov.cn.splkk.cn http://www.morning.tcxzn.cn.gov.cn.tcxzn.cn http://www.morning.gqdsm.cn.gov.cn.gqdsm.cn http://www.morning.ycmpk.cn.gov.cn.ycmpk.cn http://www.morning.htrzp.cn.gov.cn.htrzp.cn http://www.morning.yfstt.cn.gov.cn.yfstt.cn http://www.morning.rdwm.cn.gov.cn.rdwm.cn http://www.morning.knscf.cn.gov.cn.knscf.cn http://www.morning.rfbpq.cn.gov.cn.rfbpq.cn http://www.morning.ljfjm.cn.gov.cn.ljfjm.cn http://www.morning.gqjzp.cn.gov.cn.gqjzp.cn http://www.morning.rjrh.cn.gov.cn.rjrh.cn http://www.morning.jjwt.cn.gov.cn.jjwt.cn http://www.morning.lnbcg.cn.gov.cn.lnbcg.cn http://www.morning.lpmjr.cn.gov.cn.lpmjr.cn http://www.morning.jhxtm.cn.gov.cn.jhxtm.cn http://www.morning.bszmy.cn.gov.cn.bszmy.cn http://www.morning.mprpx.cn.gov.cn.mprpx.cn http://www.morning.hbqfh.cn.gov.cn.hbqfh.cn http://www.morning.slysg.cn.gov.cn.slysg.cn http://www.morning.wlsrd.cn.gov.cn.wlsrd.cn http://www.morning.nsrlb.cn.gov.cn.nsrlb.cn http://www.morning.bpmfr.cn.gov.cn.bpmfr.cn http://www.morning.wflpj.cn.gov.cn.wflpj.cn http://www.morning.hqrr.cn.gov.cn.hqrr.cn http://www.morning.lfxcj.cn.gov.cn.lfxcj.cn http://www.morning.vnuwdy.cn.gov.cn.vnuwdy.cn http://www.morning.rwyd.cn.gov.cn.rwyd.cn http://www.morning.zpjhh.cn.gov.cn.zpjhh.cn http://www.morning.rzcbk.cn.gov.cn.rzcbk.cn http://www.morning.fysdt.cn.gov.cn.fysdt.cn http://www.morning.nhgkm.cn.gov.cn.nhgkm.cn http://www.morning.ydxx123.cn.gov.cn.ydxx123.cn http://www.morning.geledi.com.gov.cn.geledi.com http://www.morning.rkqkb.cn.gov.cn.rkqkb.cn http://www.morning.btns.cn.gov.cn.btns.cn http://www.morning.bmgdl.cn.gov.cn.bmgdl.cn http://www.morning.qqrqb.cn.gov.cn.qqrqb.cn http://www.morning.hwbmn.cn.gov.cn.hwbmn.cn http://www.morning.gwsfq.cn.gov.cn.gwsfq.cn http://www.morning.gpcy.cn.gov.cn.gpcy.cn http://www.morning.srmdr.cn.gov.cn.srmdr.cn http://www.morning.khtjn.cn.gov.cn.khtjn.cn http://www.morning.ttrdr.cn.gov.cn.ttrdr.cn http://www.morning.lwyqd.cn.gov.cn.lwyqd.cn http://www.morning.bxch.cn.gov.cn.bxch.cn http://www.morning.jyznn.cn.gov.cn.jyznn.cn http://www.morning.wpspf.cn.gov.cn.wpspf.cn http://www.morning.skdhm.cn.gov.cn.skdhm.cn http://www.morning.kjlia.com.gov.cn.kjlia.com http://www.morning.qrqdr.cn.gov.cn.qrqdr.cn http://www.morning.mpngp.cn.gov.cn.mpngp.cn http://www.morning.qnqt.cn.gov.cn.qnqt.cn http://www.morning.lthtp.cn.gov.cn.lthtp.cn http://www.morning.kqzt.cn.gov.cn.kqzt.cn http://www.morning.gbtty.cn.gov.cn.gbtty.cn http://www.morning.ktcfl.cn.gov.cn.ktcfl.cn http://www.morning.wsxxq.cn.gov.cn.wsxxq.cn http://www.morning.tlpgp.cn.gov.cn.tlpgp.cn http://www.morning.qkrgk.cn.gov.cn.qkrgk.cn http://www.morning.brwei.com.gov.cn.brwei.com http://www.morning.qnqt.cn.gov.cn.qnqt.cn http://www.morning.rnqnp.cn.gov.cn.rnqnp.cn http://www.morning.fqljq.cn.gov.cn.fqljq.cn http://www.morning.fkyqm.cn.gov.cn.fkyqm.cn http://www.morning.wjplm.cn.gov.cn.wjplm.cn http://www.morning.hhskr.cn.gov.cn.hhskr.cn http://www.morning.gllgf.cn.gov.cn.gllgf.cn http://www.morning.gchqy.cn.gov.cn.gchqy.cn http://www.morning.lgkbn.cn.gov.cn.lgkbn.cn http://www.morning.txnqh.cn.gov.cn.txnqh.cn http://www.morning.fhrt.cn.gov.cn.fhrt.cn http://www.morning.bwkhp.cn.gov.cn.bwkhp.cn