Questions tagged [containskey]
80 questions
0
votes
1 answer
Java missing key message not working?
So I'm trying to display an error message when a player doesn't exist but nothing is being printed and I'm not sure what I'm doing wrong. This is the specific code below.
if (mplayer.containsKey("Carlsen, Magnus"))
{
…

DParker
- 19
- 7
0
votes
4 answers
C# Dictionary - ContainsKey Function Return Wrong Value
Im trying to use Dictionary of for mapping some words (the int doesnt really so relevant).
after inserting the word to the dic (I checked it) i try to go over the whole doc and look for a specific word.
when i do that, even if the word exist in…

michal_h
- 51
- 7
0
votes
2 answers
Increasing the hashmap value if the key already exists
I am not sure why the value doesn't increase in my code when the code already exists. Any hint is really appreciated:
import java.util.HashMap;
public class MajorityElement {
public int majorityElement(int[] nums) {
int halfSize =…

Mona Jalal
- 34,860
- 64
- 239
- 408
0
votes
1 answer
Why won't the containsKey method work as expected?
I'm trying to add up all the unique coordinates from a list of locations into a single HashMap that has the coordinate as the key, and the count as the value. The key is the longitude and latitude concatenated by the '$' symbol.
//String =…

Colby
- 313
- 4
- 13
0
votes
5 answers
How to Avoid Updating item searched by Dictionary?
In .NET WinForms C# app, I have a Dictionary collection named listItems. I store data in it on start of the app. In a static class I have as follows:
// listItems is populated bt reading a file.
// No other…

Tvd
- 4,463
- 18
- 79
- 125
0
votes
2 answers
Why hashTable contains redundant Keys
I have a problem with Hashtable; it contains redundant keys. I have redefined the equal and the hashcode, but the same problem. below is an example of my problem. I'm really need help. Thank you in advance.
public class Payoff {
public…

Sam Faith
- 175
- 5
0
votes
3 answers
How do I output my Dictionary>?
I'm really stuck here now with my Dictionary Output:
I have this Code to "fill" the dictionary (basically there are 2 of them):
Dictionary> newDictionary = new Dictionary

Luca
- 1,766
- 3
- 27
- 38
0
votes
0 answers
Searching a hashmap by overlapping dates in key
I'm guessing that I'm just going about this all wrong, but I was curious so I thought I'd ask.
I'm working on a reservation system just to brush up on some design patterns. I have a Room class and Customer class, and I want to keep a schedule of…
0
votes
2 answers
Dictionary<>.ContainsKey gives RuntimeBinderException
In .cshtml i want to check if a key exist in a Directory but i get always an error and can't find why.
This is my code:
@foreach (KeyValuePair weekAndYear in @ViewBag.WeekAndYears)
{
int key = int.Parse(weekAndYear.Value +…

Jonas B
- 29
- 5
0
votes
4 answers
Is it common practice to use dictionary to check unique element in the list?
Say I have a list of objects, object Fruit. Fruit has a property Name. i.e. Fruit1.Name = "Apple", Fruit2.Name = "Orange", Fruit3.Name = "Apple", Fruit4.Name = "Melon"... etc
List Basket = {Fruit1, Fruit2, Fruit3, Fruit4, Fruit 5...... Fruit…

Melissa Balle
- 73
- 1
- 5
0
votes
2 answers
what happend when the Map's containsKey(E e) is called in Java
i've checked the source code :
public boolean containsKey(Object key) {
Iterator> i = entrySet().iterator();
if (key==null) {
while (i.hasNext()) {
Entry e = i.next();
…

Adams.H
- 1,603
- 4
- 20
- 29
0
votes
1 answer
The given DateTime key was not present in the dictionary
I am a very beginner of C# and programming. I am trying to calculate a few DateTime variables. The first one is called dDate and second dDate1 (the previous day of dDate), third dDate2 (the second previous day of dDate, i.e., the previous day of…

BeginnedCSharp
- 39
- 1
- 2
- 10
0
votes
1 answer
Check for key in pre-existing dictionary in case insensitive manner
I want to check if a dictionary given to me contains a particular string as a key. I need to make this check in a case insensitive manner. For example if someone passes me a HTTP request object which has a dictionary of strings called headers. I…

nightcrawler
- 349
- 2
- 5
- 13
0
votes
2 answers
HashMap - using custom data objects
Suppose, I have a HashMap:
HashMap HM = new HashMap();
MyKey corresponds to a data object with two integer elements (and a constructor for passing two integers).
HM.put(new MyKey(1,1234), 1); // this seems to…

n as
- 609
- 3
- 7
- 12
0
votes
1 answer
Dictionary.ContainsKey StringComparer.Ordinal
I'm working with a Dictionary in C# with .NET 3.5. I've created a Dictionary object and passed in the StringComparer.Ordinal equality comparer. When I do the following code, however, I don't get what I would expect:
Dictionary

aaronburro
- 504
- 6
- 15