以下介绍接口:

List接口:(介绍其下的两个实现类:ArrayList和LinkedList)

ArrayList和数组非常类似,其底层①也用数组组织数据,ArrayList是动态可变数组。

① 底层:指存储格式。说明ArrayList对象都是存在于数组中。

注:数组和集合都是从下标0开始。

ArrayList有一个add(Object o)方法用于插入数组。

ArrayList的使用:(完成这个程序)

先import java.util.*;

用ArrayList在一个数组中添加数据,并遍历。

ArrayList中数组的顺序与添加顺序一致。

只有List可用get和size。而Set则不可用(因其无序)。

Collection接口都是通过Iterator()(即迭代器)来对Set和List遍历。

 package TomTexts;

     public class TomTexts_05 {
public static void main(String[] args) {
//将字符串常量作为String对象对待,实际上是将一个String对象赋值给另一个
String s1 = "Hello,java!";
//声明一个字符串,然后为其赋值
String s2;
s2 = "Hello,java!";
//使用String类的构造器中的一个。创建一个空字符串,然后赋值给它
String s3 = new String( );
s3 = "Hello,java!";
//将字符串直接传递给String类构造器来创建新的字符串
String s4 = new String("Hello,java!");
//使用String类的构造器中的一个。
//通过创建字符数组传递给String类构造器来创建新的字符串
char c1[ ] = { 'H', 'i', ',' , 'j', 'a', 'v', 'a'};
String s5 = new String(c1 );
//将字符数组子集传递给String类构造器来创建新的字符串
String s6 = new String(c1,0,2 );
System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
System.out.println(s4);
System.out.println(s5);
System.out.println(s6);
}
}

Collection接口都是通过Iterator()(即迭代器)来对Set和List遍历的更多相关文章

  1. Collection接口【集合】和Iterator迭代器类

    1.1集合的概述 前面基础学习并使用过集合ArrayList<E>,那么集合究竟是什么呢? 集合:集合是Java中提供的一种容器,可以用来存储多个数据. 那么意思就是说集合是容器,但是容器 ...

  2. Java—包装类/System类/Math类/Arrays类/大数据运算/Collection接口/Iterator迭代器

    基本类型包装类 8种基本类型对应的包装类如: 将字符串转成基本类型: 将基本数值转成字符串有3种方式: 基本类型直接与””相连接即可:34+" " 调用String的valueOf ...

  3. Java之集合初探(二)Iterator(迭代器),collections,打包/解包(装箱拆箱),泛型(Generic),comparable接口

    Iterator(迭代器) 所有实现了Collection接口的容器都有一个iterator方法, 用来返回一个实现了Iterator接口的对象 Iterator对象称作迭代器, 用来方便的实现对容器 ...

  4. Java 集合-Collection接口和迭代器的实现

    2017-10-30 00:30:48 Collection接口 Collection 层次结构 中的根接口.Collection 表示一组对象,这些对象也称为 collection 的元素.一些 c ...

  5. Java集合----概述、Collection接口、Iterator接口

    Java 集合概述 Java 集合就像一种容器,可以把多个对象的引用放入容器中. Java 集合类可以用于存储数量不等的多个对象,还可用于保存具有映射关系的关联数组 Java 集合可分为 Set.Li ...

  6. JAVA笔记17-容器之一 图、Collection接口、Iterator接口(重要)

    掌握1136: (1)1个图 (2)1个类:Collections (3)3个知识点:For(了解),Generic泛型,Auto-boxing/unboxing(自动打包/解包) (4)6个接口:C ...

  7. java学习笔记20(Arraylist复习,Collection接口方法,迭代器,增强型for循环)

    集合:集合是Java提供的一种容器,可以用来存储多个数据: 集合与数组的区别:集合的长度是可变的,数组的长度是固定的 集合中存储的数据必须是引用类型数据: ArrayList回顾: public cl ...

  8. Collection接口与Iterator接口

    Collection接口的实现类跟Vector相似.要从实现了Collection接口的类的实例中取出保存在其中的元素对象,必须通过Collection接口的Iterator()方法,返回一个Iter ...

  9. 集合--Collection接口详解&&迭代器

    /* * 集合的顶层接口--Collection接口 * 添加 * add() * addAll() * * 遍历集合 * iterator() 迭代器 * * 删除 * remove() * rem ...

随机推荐

  1. es5 - array - sort

    /** * 描述:该sort()方法对数组中的元素进行排序并返回该数组,默认排序顺序是根据字符串Unicode代码点. * 语法:arr .sort([compareFunction]) * 参数: ...

  2. react 调用项目中的 .html 文件

    (1)将 html 文件 放于 public 文件夹下 (2)window.open('about:blank').location.href="http://localhost:3000/ ...

  3. UML回想-通信图

        我们对软件project这一大块的学习事实上開始的还是挺早的,而且在后来的学习过程中也不断的涉及到了这些知识. 可是,经过软考的检验来看我对软工这一块的内容掌握的实在是慘不忍睹.基本上就是一出 ...

  4. 公用的css

    /*公共开始*/ body, ol, ul, h1, h2, h3, h4, h5, h6, p, th, td, dl, dd, form, fieldset, legend, input, tex ...

  5. 【Leet Code】Palindrome Number

    Palindrome Number Total Accepted: 19369 Total Submissions: 66673My Submissions Determine whether an ...

  6. centos下 安装jdk

    JDK 1.7下载地址 http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html JDK ...

  7. 动态修改Spring定时器

    spring 的Quartz定时器的功能非常强大,可以在特定的年月日小时分秒的时间点触发时间,完成事件的调度,就像windows中得计划任务一样.下面看一个典型的Quartz定时器的实现:   1.首 ...

  8. RMAN Recovery Catalog

    RMAN用来存放数据库元数据的schema. the catalog includes the following types of metadata:-Data file and archived ...

  9. WebSocket 学习--用nodejs搭建服务器

    最简单的socket服务端 var net = require("net"); server1 = net.createServer(function(client){ clien ...

  10. php比较函数,判断安全函数

    一.字符串比较函数: int strcasecmp ( string $str1 , string $str2 ) int strcmp ( string $str1 , string $str2 ) ...