Java视频学习笔记:基础(四)之对象容器

ArrayList

import java.util.ArrayList;

...
//  定义 test是用来存放String类的ArrayList容器
ArrayList<String> test = new ArrayList<String>(); //容器类型<元素类型>

//  增
test.add("world");
test.add(0,"hello");

//  删
String removedString = test.remove(0); //返回被删除的内容 hello

//  获取
String s = test.get(0);     //  world
int tSize = test.size();    //  1   

//  打印
System.out.println(test);   //  [world]

//  ArrayList容器 -> String数组
String[] arr = new String[test.size()];
test.toArray(arr);

集合容器
集合就是数学中的集合的概念,所有的元素都具有唯一的值,元素在其中没有顺序。eg. HashSet

Hash表
HashMap

HashMap<Integer, String> hm = new HashMap<Integer, String>();   //  <key, value>
hm.put(20180314, "zhangsan");   //  增
boolean isExist = hm.containsKey(20180314); //  key是否存在
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值