Java基础学习笔记之七(4)--Iterator&Comparable

***Iterator 接口  

  Iterator对象称作迭代器用以方便的实现对容器内元素的
遍历操作。  
  1.boolean hasNext()
  Returns true if the iteration has more elements.
  如果迭代器中还有元素可以迭代,则返回true
  (判断游标右边是否还有元素可以迭代)
  
  2.E next()
  Return the next element in the iteration.
  返回迭代的下一个元素
  (返回游标右边的元素,并将游标移动到下一个位置)
  
  3.void remove()
  Removes from the underlying collection the last element
return by the iteration.
  删除从迭代器中指向的当前元素
  (iterator对象的remove方法是在迭代过程中删除元素的
唯一安全的方法)

***Comparable 接口

  所有需要排序的类,都需要实现java.lang.Comparable接口。
重写compareTo方法。
  1.public int compareTo(T obj);
  Compares this object with the specified object for order.  
  比较此对象与指定对象的顺序
  
  返回0表示    this==obj
  返回正数表示 this>obj
  返回负数表示 this<obj

你可能感兴趣的:(Java基础学习笔记之七(4)--Iterator&Comparable)