问题标签 [keyset]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
java - 输出Java map的前几个key
我想打印出 Java 映射的前几个键(不是值,不是所有键)。例如,如何输出前 10 个键?
java - Map 不支持的 add/addAll 操作.keySet()
关于Map<K,V>
界面:
为什么keySet()
返回一个Set
支持remove
运算却不支持add()
andaddAll()
运算的?
java - java.util.HashMap.KeySet 在 java.util.HashMap 中不公开;无法从外部包访问
在 REPL 中使用地图来测试功能并在尝试在地图上运行 .isEmpty() 函数时收到此消息。
以下是创建地图后在控制台中输入的内容:
知道是什么原因造成的吗?我只是想在 REPL 中对我的地图进行故障排除,而不是一个实际的程序,但我对此错误消息感到好奇,因为我认为 .isEmpty() 已内置于地图的功能中。
谢谢!
java - 如何在 Junit (Java) 中测试集合
我需要实现一个稀疏图并对其进行一些junit测试。
这是我的图表类:
这是我的测试:
我的问题是,如何创建一个测试来检查我的集合中是否存在所有顶点?
我尝试将字符串与 keySet 进行比较,但错误是应该是字符串,但方法 assertEquals 得到了 keySet。
java - JSONObject keySet() function not there?
Very confused. New project, add this code:
.keys()
method resolves as it should.
.keySet()
method highlights red with AndroidStudio giving "Cannot resolve method keyset()" error.
If i go to keys() definition, here they both are public and all: http://goloskok.com/u/2015-07-01_16-41-08.jpg
What am I doing wrong?
android - 如何在不迭代的情况下获取hashmap的单独键和值
这里的键是纬度和经度的差异,值是字符串值的列表。我想做单独的哈希图的键和值。
有可能这样做吗???请给我建议。
MainActivity.java
我不想对 keyset() 使用迭代或循环。如何在没有迭代的情况下使用?
java - 来自文本文件的 java hashmap 字数
我正在尝试编写代码以从文本文件中读取信息,我需要找出每个由空格分隔的单词出现了多少次。然后我需要按字母顺序输出每个单词的计数。我希望使用 TreeMap、keySet() 和 Iterator。我的代码非常不完整,我很困惑。
}
android - Application stops when clicked on item in ExpandableListview Android
I'm trying to create an ExpandableListView, below is my code for creating data for the expandable list
When I'm debugging it, the hashDataChild has the values of what I'm expecting to have where each header has 3 child in it. But when trying on my phone it crashes and it doesn't show anything in logcat. The reference I'm using for creating an expandable listview is [this]:http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
I was thinking that it might be because the ExpandableListview OnGroupClickListener is not working? How can I solve this? It goes inside my onGroupClick but doesn't show the list of child
Below is my code for my Expandable Adapter
Thank you so much for the help.
Update
I have tried returning true in my onGroupClick() and hashDataChild.get( arrayList.get(groupPosition)) is null why is it like that even if when checking the arrayList it has value?
i think i found the reason why using this
my hashDataChild doesn't contain key i don't know why and how to solve it any ideas why it is like that? even if when I'm debugging it does shows its keys and value of my arrayList?
I've change the containsKey and used String.valueOf(arrayList.get(groupPosition))
as suggested. But my child data still doesn't show up and return false in onGroupClick()
it still closes my application.
java - 为什么 HashMap.keySet() 不返回空集
里面的钥匙keySet
从哪里来?该类KeySet
是 的内部类HashMap
,它可以访问HashMap
变量,但没有像 aSet<K>
这样的直接变量,它只存储要引用的映射键。
我只能找到一张Entry<K,V>[]
桌子。但它已经存储了键和值。当调用该方法进行引用时
,该方法是否会keySet()
执行某些操作?new KeySet()
可能是这样的:
那么keySet存储的keys,当添加或删除一个key-value时,它也会添加或删除keySet
相同的keys吗?
源代码只显示一个new KeySet()
,但为什么它不是空的,但有键?为了更清楚:
在每一行调试和断点,检查每一行并观察 map 的 keySet 变量会显示上面的结果,对吗?
一旦 keySet() 被调用,put 和 remove 对 keySet 的效果是一样的,对吧?我已经查看了 HashMap 的 put 和 remove 方法。
对于“put()”,如果调用 addEntry -> createEntry -> 在调用“table[bucketIndex] = new Entry<>(hash, key, value, e);”之后 keySet 将添加密钥,
for "remove()" ->removeEntryForKey -> 调用 table[i] = next; keySet中的key被删除了,所以我认为table[]和keySet之间一定有某种关联,然后我问了这个问题......