快速业务通道

JAVA容器小结 - 编程入门网

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-06-24
ub)); System.out.println(); List<Pet> copy = new ArrayList<Pet>(pets); sub = Arrays.asList(pets.get(1),pets.get(4)); System.out.print("sub: " + sub); System.out.println(); copy.retainAll(sub); System.out.print("13: " + copy); System.out.println(); copy = new ArrayList<Pet>(pets); copy.remove(2); System.out.print("14: " + copy); System.out.println(); copy.removeAll(sub); System.out.print("15: " + copy); System.out.println(); copy.set(1, new Mouse());//Replace an element System.out.print("16: " + copy); System.out.println(); copy.addAll(2, sub); System.out.print("17: " + copy); System.out.println(); System.out.print("18: " + pets.isEmpty()); System.out.println(); pets.clear(); System.out.print("19: " + pets); System.out.println(); System.out.print("20: " + pets.isEmpty()); System.out.println(); pets.addAll(Pets.arrayList(4)); System.out.print("21: " + pets); System.out.println(); Object[] o = pets.toArray(); System.out.print("22: " + o[3]); System.out.println(); Pet[] pa = pets.toArray(new Pet[0]); System.out.print("23: " + pa[3].id()); System.out.println(); } }

JAVA容器小结(2)

时间:2010-01-06

运行结果:

1: [Rat, Manx, Cymric, Mutt, Pug, Cymric, Pug] 2: [Rat, Manx, Cymric, Mutt, Pug, Cymric, Pug, Hamster] 3: true 4: 2 5: -1 6: false 7: true 8: [Rat, Manx, Mutt, Pug, Cymric, Pug] 9: [Rat, Manx, Mutt, Mouse, Pug, Cymric, Pug] sublist: [Manx, Mutt, Mouse] 10: true sorted sublist: [Manx, Mouse, Mutt] 11: true shuffle sublist: [Mouse, Manx, Mutt] 12: true sub: [Mouse, Pug] 13: [Mouse, Pug] 14: [Rat, Mouse, Mutt, Pug, Cymric, Pug] 15: [Rat, Mutt, Cymric, Pug] 16: [Rat, Mouse, Cymric, Pug] 17: [Rat, Mouse, Mouse, Pug, Cymric, Pug] 18: false 19: [] 20: true 21: [Manx, Cymric, Rat, EgyptianMau] 22: EgyptianMau 23: 14

2 LinkedList

LinkedList也像ArrayList一样实现了基本的List接口,但是它执行某些操作(比如插入、删除)时要比ArrayList更加的高效,但是在随机访问操作方面要逊色一些。此外,LinkedList还添加了可以使其用作栈、队列或双端队列的方法。下面是关于LinkedList使用的例子:

/**//* * @(#)LinkedListFeatures.java  1.0 May 18, 2008 * @author:Administrator * Copyright 2008 CSS WEB Microsystems, Inc. All rights reserved. * CSS WEB ROOM PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package holding; import java.util.LinkedList; import static net.mindview.util.Print.*; import typeinfo.pets.Hamster; import typeinfo.pets.Pet; import typeinfo.pets.Pets; import typeinfo.pets.Rat; public class LinkedListFeatures ...{ public static void main(String[] args) ...{ LinkedList<Pet> pets = new LinkedList<Pet>(Pets.arrayList(5)); print(pets); print("pets.getFirst(): " + pets.getFirst()); print("pets.element(): " + pets.element()); print("pets.peek(): " + pets.peek()); print("pets.remove(): " + pets.remove()); print("pets.removeFirst(): " + pets.removeFirst());

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号