Collection接口常用方法
来源:互联网 发布:sql 比较运算符 编辑:程序博客网 时间:2024/05/18 03:54
package com.lwz;
import java.util.*; //导入包public class Muster {
public static void main(String[] args) {
Collection<String>list=new ArrayList<>();//实例化结合对象
list.add("a");//向集合添加数据
list.add("b");
list.add("c");
list.add("def");
Iterator<String> it=list.iterator();//创建迭代器
while(it.hasNext()){//判断是否右下一个元素
String str=(String)it.next();//获取集合中元素
System.out.print(str);
}
System.out.println();
System.out.println("元素个数为:"+list.size());//判断集合中元素个数
list.remove("b");//从集合中移除"b"
System.out.println("剩余元素个数为:"+list.size());//判断集合中元素个数
Iterator<String> it1=list.iterator();//创建迭代器
while(it1.hasNext()){//判断是否右下一个元素
String str=(String)it1.next();//获取集合中元素
System.out.print(str);
}
System.out.println();
System.out.println("当前集合是否为空:"+list.isEmpty()); //判断当前集合是否为空
}
}
0 0
- Collection接口常用方法
- Collection接口常用的方法
- Collection接口的常用方法
- Java集合类:Collection接口常用方法
- Java Collection接口的常用方法
- Collection接口和List接口中常用的方法
- Collection接口方法
- Collection接口基本方法
- Collection接口集合方法
- Collection常用方法
- Collection常用方法
- java中集合类中Collection接口中的List接口的常用方法熟悉
- java中集合类中Collection接口中的Set接口的常用方法熟悉
- java中集合类中Collection接口中的Map接口的常用方法熟悉
- collection中的方法和接口
- 实现Collection和Map接口的常用类的几种循环方法
- 集合collection常用方法定义
- Java学习之容器上(Collection接口常用方法,Iterator接口,使用foreach循环遍历Collection集合元素,Set集合通用知识(Hashset类,hashcode()与Lin
- Java File类和IO流
- 微信通信协议,用自己的程序收发微信,微信网页web版分析
- 计算机网络常见面试题
- Java 变量-基本类型
- 半导体设备数据Handshake
- Collection接口常用方法
- 强化学习读书笔记
- OkHttp源码阅读之旅(一)
- leetcode83~Remove Duplicates from Sorted List
- tomcat什么鬼,apache tomcat 一种服务器了咦
- 强化学习读书笔记_0
- Java初始化
- GYM 101149 A.Balls in Urn(水~)
- Node JS 中遇到过的问题