如何在LinkedHashMap中的特定索引/位置添加元素? [英] How to add element at specific index/position in LinkedHashMap?

查看:6977
本文介绍了如何在LinkedHashMap中的特定索引/位置添加元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有序的LinkedHashMap,我想在特定的索引添加元素,说在地图的第一个地方或最后一个地方。
如何在LinkedHashMap中在特定位置添加元素?

I have an ordered LinkedHashMap and i want to add element at specific index , say at first place or last place in the map. How can i add element in LinkedHashMap at an specific position?

即使我可以在LinkedHashMap中向FIRST或LAST位置添加元素也会有帮助!

Even if I could add an element to FIRST or LAST position in LinkedHashMap would help!

推荐答案

您无法更改订单。此构造函数为 insert-order (默认情况下)或访问顺序

You can not change the order. It is insert-order (by default) or access-order with this constructor:


public LinkedHashMap(int initialCapacity,float loadFactor,boolean accessOrder)


  • 构造具有指定初始容量,负载因子和排序模式的空LinkedHashMap实例。

  • Constructs an empty LinkedHashMap instance with the specified initial capacity, load factor and ordering mode.

参数:
initialCapacity - 初始容量
loadFactor - 加载因子
accessOrder - 排序模式 - 对于访问顺序为true,对插入顺序为false

Parameters: initialCapacity - the initial capacity loadFactor - the load factor accessOrder - the ordering mode - true for access-order, false for insertion-order

抛出:
IllegalArgumentException - 如果初始容量为负值或负载因子为非正值

Throws: IllegalArgumentException - if the initial capacity is negative or the load factor is nonpositive

请参阅: LinkedHashMap

这篇关于如何在LinkedHashMap中的特定索引/位置添加元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆