zoukankan      html  css  js  c++  java
  • 14.2 Collection接口

    1、概述

      Collection接口是层次结构中的跟接口。构成Collection的单位称为元素。Collection接口通常不能直接使用,但该接口提供了添加元素、删除元素、管理数据的方法。由于List接口与Set接口都继承了Collection接口因此这些方法对List集合与Set集合是通用的。
      注意:(1)、Collection接口中的iterator()方法可返回在此Collection进行迭代的迭代器。
            (2)、 Iterrator的next()方法返回的是Object。

    Collection接口的常用方法:

    方法 功 能 描 述
    add(E e) 将指定的对象添加到该集合中
    remove(Object o) 将指定的对象从该集合中移除
    isEmpty() 返回boolean值,用于判断当前集合是否为空
    iterator() 返回在此Collection的元素上进行迭代的迭代器。用于便利集合中的对象
    size() 返回int型值,获取该集合中元素的个数
     1 package com.lzw;
     2 import java.util.*;
     3 
     4 public class Muster {
     5     public static void main(String[] args) {
     6         Collection<String> list = new ArrayList<>();    //实例化集合类对象
     7         list.add("a");
     8         list.add("b");
     9         list.add("c");
    10         list.add("d");
    11         list.add("e");
    12         
    13         Iterator<String> it = list.iterator();      //创建迭代器
    14         
    15         //遍历循环
    16         while(it.hasNext()) {
    17             String str = (String)it.next();        //获取集合中的元素
    18             System.out.println(str);
    19         }
    20     }
    21 }
    View Code

  • 相关阅读:
    urlencode 和 rawurlencode 的区别
    magic_quotes_gpc
    变量的值是多少
    git diff patch
    drupal前端开发的第一点
    git drupal eclipse
    spm总结
    features block
    alu features menu
    git reset 理解
  • 原文地址:https://www.cnblogs.com/studycode/p/9536544.html
Copyright © 2011-2022 走看看