黑马程序员技术交流社区

标题: List三个子类的特点: [打印本页]

作者: 沙迦    时间: 2015-4-24 23:29
标题: List三个子类的特点:
*
* List三个子类的特点:
        同步 -- 安全 -- 效率低
* List:
*                 |--ArrayList
*                         底层数据结构是数组,查询快,增删慢
*                         线程不安全,效率高。
*                 |--Vector
*                         底层数据结构是数组,查询快,增删慢
*                         线程安全,效率低。
*                 |--LinkedList
*                         底层数据结构是链表,查询慢,增删快
*                         线程不安全,效率高。
*                 请问,以后我们到底用他的哪个子类呢?
*                 想安全吗:
*                         想:Vector
*                         不想:ArrayList和LinkedList
*                                 查询多:ArrayList
*                                 增删多:LinkedList
*                你根本不会分析,不知道用谁。用ArrayList。
        public class ListDemo {
        public static void main(String[] args) {
                // 用ArrayList
                // List list = new ArrayList();
                // 用Vector
                //List list = new Vector();
                //用LinkedList
                List list = new LinkedList();
               
                list.add("hello");
                list.add("world");
                list.add("java");

                Iterator it = list.iterator();//迭代器迭代
                while (it.hasNext()) {//判断时候下一个 元素是否存在
                        String s = (String) it.next();//强转获取到的元素
                        System.out.println(s);打印元素集合
                }
作者: 马士基    时间: 2015-4-25 00:11
用自己的话说出来才是王道,笔记是死的人是活的
作者: 奋斗的黑马    时间: 2015-4-25 00:21
哈哈,,没事没事,,会用就好了  ,能把不明白的讲明白也很不错的
作者: Richard926    时间: 2015-4-25 00:25
顶!!!!!!




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2