zoukankan      html  css  js  c++  java
  • List接口方法

     1 package cn.zhou.com;
     2 /*
     3 * List?-------是啥? Collection 的一个子接口!
     4 * 
     5 * 集合?容器?
     6 * 
     7 * 区分容器,每个容器的数据结构不一样!
     8 * 集合,数据存储的一种方式?
     9 * 
    10 * 不断地向上抽取 ,出现体系,形成了集合框架!
    11 * 
    12 * list是集合框架中的接口!1
    13 * 
    14 * 顶层!Collection; 要学会 看顶层 用底层!
    15 * 
    16 * Collection :
    17 * |--list 有序的,带索引的,通过索引可以精确的操作集合中的元素,元素是可以重复的!
    18 * |--set
    19 * 
    20 * List 方法------>add() get() remove(); set()都是围绕索引进行的!
    21 * 插入    获得    删除    修改
    22 * 
    23 * 
    24 */    
    25 import java.io.ObjectInputStream.GetField;
    26 import java.util.ArrayList;
    27 import java.util.Iterator;
    28 import java.util.List;
    29 
    30 public class ListDemo {
    31 public static void main(String[] args) {
    32 listText();
    33 }
    34 public static void listText(){
    35 List list=new ArrayList();
    36 
    37 //在集合中添加元素!
    38 list.add(new Student("张三01",45));
    39 list.add(new Student("张三02",45));
    40 list.add(new Student("张三03",45));
    41 
    42 
    43 
    44 //1.在集合中插入元素! 改变集合的长度!
    45 list.add(1,new Student("张晓",22));
    46 
    47 //5.修改元素
    48 list.set(1, new Student("张三的孩子",15));
    49 
    50 //2.remove(num) 删除集合中的元素! num 决定删除那个角标!
    51 //    list.remove(1);
    52 
    53 
    54 //3.获得集合中的元素!
    55 Object object=list.get(0);
    56 for (int i = 0; i < list.size(); i++) {
    57 System.out.println("get["+i+"]="+list.get(i));
    58 }
    59 
    60 //4.遍历数组 获得集合中的元素!
    61 for (Iterator it = list.iterator(); it.hasNext();) {
    62 Student stu = (Student) it.next();
    63 System.out.println(stu);
    64 
    65 }
    66 
    67 //    System.out.println(object);
    68 }
    69 }
  • 相关阅读:
    springMVC 错误页面配置
    设计模式 11 —— 代理模式
    JAVA RMI 实例
    设计模式 10 —— 状态模式
    设计模式 9 —— 模板方法模式
    Java EE : 三、图解Session(会话)
    Java EE : 二、图解 Cookie(小甜饼)
    Java EE : 一、图解Http协议
    《JAVA与模式》之单例模式
    Java中如何克隆集合——ArrayList和HashSet深拷贝
  • 原文地址:https://www.cnblogs.com/ZXF6/p/10571690.html
Copyright © 2011-2022 走看看