zoukankan      html  css  js  c++  java
  • SA9 collections

     【定义】

     表示object的集合

    generic class:可以用于多种object, 

     

     

    抽象类的具体实现:

     【ArrayList】

    动态添加,只能加Non-primitive type,要初始化长度。 

     

     

    【compare】记忆方法:BT1 用this,T02 用object

    comparable:比较natural order,comparator的compare可以比较2个物体,定义不同的order

    public void sortAndPrint() {
    Collections.sort(books); //natural order
    printCollection();
    Collections.sort(books, new AuthorComparer());
    printCollection();
    Collections.sort(books, new YearComparer());
    printCollection();
    }
    //inner classes
    public class AuthorComparer implements Comparator <Book> {
    public int compare(Book b1, Book b2) {
    return b1.author.compareTo(b2.author);
    }}
    public class YearComparer implements Comparator <Book>  {
    public int compare(Book b1, Book b2) {
    return (b1.year - b2.year); 
      }
    }}

     【iterator】

    【Arraylist】

    只存了引用,元素的位置随意。

    Java offers only doubly linked list data structure. If you needed a circular or a singly linked list in your program, 

    Create my own custom-made linked list。只有双向链表。

     

     

  • 相关阅读:
    《大道至简》3
    《大道至简》2
    《大道至简》1
    [转]python 中的字符串连接
    [转]Eclipse Python插件 PyDev 使用
    [转]Windows下python环境变量配置
    [转]aircrack-ng破解教程
    [转]Java获取当前路径
    [转]java程序打包成jar,图片文件问题
    关于2013,致2014
  • 原文地址:https://www.cnblogs.com/immiao0319/p/9813561.html
Copyright © 2011-2022 走看看