@Test
public void removeElementFromMap()
{
Map<Integer, String> test = new HashMap<Integer, String>();
test.put(1, "a");
test.put(2, "b");
test.put(3, "c");
test.put(4, "d");

Iterator<Entry<Integer, String>> it = test.entrySet().iterator();

int key = 0;
while (it.hasNext())
{
key = it.next().getKey();
if (key == 1)
{
it.remove();
}
}

System.out.println(test);
}

删除List集合元素:

@Test
public void removeElementFromList()
{
List<Integer> testList = new ArrayList<Integer>();
testList.add(1111);
testList.add(2222);
testList.add(3333);
testList.add(4444);

Iterator<Integer> it = testList.iterator();

int value = 0;
while (it.hasNext())
{
value = it.next();
if (value == 1111)
{
it.remove();
}
}
}

删除map、list集合元素总结的更多相关文章

  1. for循环中删除map中的元素,valgrind检测提示error:Invalid read of size 8

    #include <iostream> #include <map> using namespace std; class A { public: typedef std::m ...

  2. Java集合——遍历集合元素并修改

    Java集合——遍历集合元素并修改 摘要:本文主要总结了遍历集合的方式,以及在遍历时修改集合要注意的问题. 遍历Collection 对List和Set的遍历,有四种方式,下面以ArrayList为例 ...

  3. Java中删除第一个集合中以某某开头的元素,删除第二个集合中以某某结尾的元素,并合并成一个集合

    import java.util.ArrayList; import java.util.List; public class Test { public static void main(Strin ...

  4. js删除map中元素

    js中删除map中元素后,map的长度不变,这时需要我们自己处理 delete vacc[0]; delete vacc[1]; ClearNullArr(vacc); //清除vacc中的null值 ...

  5. 根据key删除Map集合中的key-value映射

    一:在遍历Map时是不可以删除key-value映射的,如果根据key删除,如下: public static void main(String[] args) { Map<String,Obj ...

  6. MyBatis3_[tp-26-27]_映射文件_select_返回List_记录封装Map:返回单个元素的Map或者整体Map集合

    笔记要点出错分析与总结工程组织 1.定义接口 public interface EmployeeMapper { //多条记录封装到一个map中: Map<Integer,Employee> ...

  7. 删除集合元素Collection ,remove()

    package seday11;/*** @author xingsir*/public class coordinate { private int x; private int y; /* * 右 ...

  8. Java——删除Map集合中key-value值

    通过迭代器删除Map集合中的key-value值 Iterator<String> iter = map.keySet().iterator(); while(iter.hasNext() ...

  9. Java中如何优雅地删除List中的元素

    在工作中的许多场景下,我们都会使用到List这个数据结构,那么同样的有很多场景下需要删除List中的某一个元素或某几个元素,那么我们该如何正确无误地删除List中的元素的,今天我来教大家三种方式. 前 ...

随机推荐

  1. MongoDB 集合命令

    集合命令 创建语法如下 name是要创建的集合的名称 options是一个文档,用于指定集合的配置,选项​​参数是可选的,所以只需要到指定的集合名称 可以不手动创建集合,向不存在的集合中第一次加入数据 ...

  2. Spring Cloud feign

    Spring Cloud feign使用 前言 环境准备 应用模块 应用程序 应用启动 feign特性 综上 1. 前言 我们在前一篇文章中讲了一些我使用过的一些http的框架 服务间通信之Http框 ...

  3. linux下挂载磁盘操作

      重启服务器,查看是否挂载上去了 CentOS云服务器数据盘分区和格式化 腾迅云: http://wiki.qcloud.com/wiki/CentOS%E4%BA%91%E6%9C%8D%E5%8 ...

  4. poj1015 正解--二维DP(完全背包)

    题目链接:http://poj.org/problem?id=1015 错误解法: 网上很多解法是错误的,用dp[i][j]表示选择i个人差值为j的最优解,用path[i][j]存储路径,循环次序为“ ...

  5. Ubuntu 分辨率更改 xrandr Failed to get size of gamma for output default

    sudo vim /etc/xorg.conf copy: Section "Monitor" Identifier "Monitor0" VendorName ...

  6. 1.Two Sum (Array; HashTable)

    Given an array of integers, find two numbers such that they add up to a specific target number. The ...

  7. Linked dylibs built for GC-only but object files built for retain/release for architecture x86_64

    编译开源Xcode 插件 SCXcodeSwitchExpander 源码地址: https://github.com/stefanceriu/SCXcodeSwitchExpander 编译环境:X ...

  8. mysql数据库的最基本的命令

    #查看mysql有哪些数据库:show databases; 创建一个数据库名称为DataBaseName,字符编码为utf8支持中文create database DataBaseName char ...

  9. Spring整合Struts2框架的第二种方式(Action由Spring框架来创建)(推荐大家来使用的)

    1. spring整合struts的基本操作见我的博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2框架整 ...

  10. Linux 常用环境变量

    /etc/profile.d/start.sh # java export JAVA_HOME=/usr/local/jdk export CLASSPATH=.:$CLASSPATH:$JAVA_H ...