All Questions
Tagged with enumeration collections
43 questions
0
votes
1
answer
28
views
Collection.Count shows zero even though Collection.GetEnumerator.Current contains a reference after MoveNext()
Note: An answer in either VB.NET or C# will be fine. I have no preference for this Q&A.
I'm trying to test my networking code and I'm running into a very strange problem: the GatewayAddresses ...
1
vote
0
answers
18
views
WriteXml - Collection was modified; enumeration operation might not execute
I'm coding in Visual Studio 2019 and I get the following error message: "Collection was modified; enumeration operation might not execute".
It happens when I try to save a dataset with the ...
0
votes
1
answer
53
views
Code for #into: is related to the code for #inject:into: , but must be solving a different problem. Explain the difference?
What does this do, and is there a simpler way to write it?
Collection>>into: a2block
| all pair |
all := ([:allIn :each| allIn key key: allIn value. each])
-> (pair := nil -...
0
votes
1
answer
95
views
How to implement a function that returns an "enumeration" of objects?
I am working on a project about design patterns using Java. The class diagram before using the design patterns is provided in the link. Since I am new to Java, some of the classes methods descriptions ...
-3
votes
2
answers
340
views
The Collection has modified, the enumeration operation may not execute
I have a dictionary of which I want to modify the key by removing the previous one and adding a new one and then Iterating over it again and again.
Here is the declaration of dictionary
Dictionary&...
0
votes
1
answer
213
views
How to update the dictionary from the user input and sort according to values using python?
I have dictionary below
{0: {'STATE': 'AL',
'POPULATION': '151449859682',
'TOP_CITY': '1',
'RANK': '1'},
1: {'STATE': 'NY',
'POPULATION': '8955557',
'TOP_CITY': '6',
'...
0
votes
1
answer
127
views
Changing a collection.Counter during enumeration? [duplicate]
counter = Counter()
// fill data into counter
for a, b in counter.most_common():
if (b > 1):
counter[a] = np.log(b)
else:
counter[a] = -np.log((1 / (b+0.01)))
As I see, ...
0
votes
4
answers
131
views
Flag empty collection or enumerate over members if collection is not empty (C#)
The obvious solution (to me) is the following:
if (widgets.Count == 0)
{
//Handle empty collection
}
else
{
// Handle non-empty collection
foreach (widget in widgets)
{
// ...
0
votes
1
answer
100
views
Why Collections.enumeration comes with enumeration() method
In Collections Framework, we have the Iterator and ListIterator interfaces, which are used for iterating data structures. They provide full functionality for iteration. But I wonder that why the JDK ...
1
vote
3
answers
405
views
Iterate/enumerate over part of a list?
Is there a way to remember the position of an enumerator?
I want to remember the position of an enumerate, so that I can reset it to a position before the current. I don't want to go back to the ...
0
votes
1
answer
72
views
Enumeration Interface's elements() method
How the statement return new Enumeration() is possible, since Enumeration is an Interface. Plz explain. Thanks.
public Enumeration<E> elements() {
return new Enumeration<E>() {
...
0
votes
1
answer
4k
views
How to correctly insert all the enum values into an hashset?
I have the following problem in Java.
I have this eunm that contains 2 values that represent 2 String values "COORDINATION" and "PISC" :
private enum exclusion {COORDINATION, PISC};
So I have ...
0
votes
0
answers
25
views
IEnumerable interface definition [duplicate]
I took a look at the definition of the IEnumerable interface
public interface IEnumerable
{
// Summary:
// Returns an enumerator that iterates through a collection.
//
...
-1
votes
2
answers
134
views
Implementing Enumerations interface to Print a class Object
This is my source code. I want to traverse a Vector using the Enumeration interface. If I simply traverse the Vector, I get hash codes of objects and if I implement interface Enumeration on the class ...
0
votes
2
answers
248
views
Prevent collection from being modified while enumerating
how do i prevent Collection from being modified during Enumeration.
Here is the class source code.
public class cars : IEnumerator,IEnumerable
{
private car[] carlist;
int position = -1;
...
0
votes
2
answers
293
views
Custom collection/enumeration - how to filter returned collection?
Currently I have the following code...
For Each Ord as clsOrder in Orders
If NOT Ord.Status = voided then
'do stuff to all orders that are not voided...
endif
Next
What I am wondering is ...
1
vote
3
answers
389
views
difference between iterator and enumeration
see the below code
import java.util.Enumeration;
import java.util.Vector;
public class Modification_On_Eumeration {
public static void main(String[] args) {
Vector<Integer> vector ...
-1
votes
5
answers
4k
views
retriving elements using enumeration
see the below code,I am retriving elements from vector and printing using enumeration.
package com.rajeev.enumeration;
import java.util.Enumeration;
import java.util.Vector;
public class ...
-1
votes
3
answers
585
views
Does Enumeration only work in legacy collection framework classes? [closed]
Can anyone give confirmation that Enumeration only works with legacy collection framework classes?
I tried to retrieve elements of Vector and Stack using Enumeration, it works.
Stack<Integer> ...
0
votes
1
answer
584
views
Access one object from an object collection
Using this function:
public bool CheckCallerStatus(string stConsumerName)
{
SelectQuery selectQuery = new SelectQuery("select ExecutablePath from Win32_Process where name='" +
...
4
votes
1
answer
455
views
Confusion about collections, enumeration, and iterator in Java
My textbook barely talks about enumeration in Java, and the videos that I've watched don't explain much. So from what I'm understanding, enumeration is like a whole different class
where you can ...
0
votes
1
answer
224
views
Unable to Iterate through a hashtable using enumeration in java
This is the code where I am trying to print the key but it never gets executed rather it just goes to the the last line and throws null pointer exception.
Enumeration<String> keys = states.keys(...
2
votes
3
answers
613
views
Modifying a collection while enumerating another one
I want to delete every coin that has the delete boolean set to true, and I know I can't delete it from the same collection the foreach is iterating over. So I made a copy (temp) but it keeps throwing ...
1
vote
3
answers
61
views
Is it possible to parse List using Enumeration?
Is it possible to pass List using Enumeration?
List<Integer> l = new ArrayList<>();
l.add(1);
l.add(5);
l.add(112);
Enumeration<Integer> e;
How i can get all the list into ...
0
votes
1
answer
171
views
Iteration in Dictionary
I have a dictionary i have to check a condition till last element of dictionary.I have used method movenext but it is throwing exception.What i wanted to do is when element in array B comes.Compare ...
0
votes
2
answers
628
views
C# Collection was modified exception on lambda.where
I have the following code:
var actionsToExecute = _messagesToExecute.Where(m => m.CanExecute).ToList();
It runs fine 99% of the time, but every once in a while it will crash with the exception:
...
4
votes
2
answers
2k
views
Error when using foreach on dictionary which contains objects as value
I'm trying to iterate over a dictionary which contains objects as value:
foreach (KeyValuePair<int, CMapPool_Entry> Entry in MapPool)
{
this.SendConsoleMessage(Entry.Value.Map);
}
Below you ...
-2
votes
1
answer
4k
views
It is said that Enumeration is little faster then Iterator why?
Why enumeration is faster then Iterator ? though we have more advantages with iterator then enumeration.
1
vote
1
answer
948
views
Ninject throwing "Collection was modified; enumeration operation may not execute" error
I am using the following 2 Ninject assemblies in my web project.
Ninject.dll – Version 2.2.0.0
Ninject.Web.dll – Version 2.2.0.4
I have noticed that when I perform load testing on the server I am ...
2
votes
3
answers
765
views
Best way to enumerate collection when elements may be deleted during enumeration [duplicate]
There is a typical collection of some class objects e.g. string for a simplicity
IList<string> collection = new List<string>();
During the program flow some function needs to operate on ...
57
votes
3
answers
50k
views
Java: Enumeration from Set<String>
I have a simple collections question. I have a Set<String> object. I want an Enumeration<String> of the Strings in that Set. I need an Enumeration<String> since I am overriding a ...
2
votes
2
answers
2k
views
Avoid Collection has been modified error
Issue:
I have the following code:
foreach(var ItemA in GenericListInstanceB)
{
ItemA.MethodThatCouldRemoveAnyItemInGenericListInstanceB();
}
Obviously i get an error.
What i want to do is ...
0
votes
3
answers
4k
views
Java generics for Enum types
I am trying to write a Java class, one part of which requires a mapping of the values of an unknown enum to another class. My class contains a field private Map<? extends Enum, Unit> myMap and ...
10
votes
6
answers
22k
views
C# - Change value of dictionary key-value pair while in foreach
I have this code which is being run every frame of a game:
foreach (var repeaterAction in conditionTimes.Keys)
{
if (repeaterAction.Condition() == true)
{
if (...
11
votes
10
answers
23k
views
C# preventing Collection Was Modified exception
Does
foreach(T value in new List<T>(oldList) )
is dangerous (costly) when oldList contains 1 millions of object T ?
More generaly what is the best way to enumerate over oldList given that ...
2
votes
4
answers
417
views
Get Current Index for Removal in String Collection
I have a String Collection that is populated with ID's like so -->
12345
23456
34567
and so on. What I need to do is at the user's request, and when certain parameters are met, go through that list,...
81
votes
9
answers
183k
views
Collection was modified; enumeration operation may not execute in ArrayList [duplicate]
I'm trying to remove an item from an ArrayList and I get this Exception:
Collection was modified; enumeration operation may not execute.
Any ideas?
2
votes
2
answers
235
views
Enumerating a collection, then modifying it, what is the precedent for throwing an exception?
When enumerating a .NET collection, MSDN states that:
An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or ...
1
vote
4
answers
361
views
Point of need of custom Enumerators
When reading a post some points were given without example :
To implement IEnumerable / IEnumerable, you must provide an enumerator :
•If the class is "wrapping" another collection, by returning ...
141
votes
10
answers
99k
views
Difference between Java Enumeration and Iterator
What is the exact difference between these two interfaces? Does Enumeration have benefits over using Iterator? If anyone could elaborate, a reference article would be appreciated.
13
votes
6
answers
7k
views
Enumerate through a subset of a Collection in C#?
Is there a good way to enumerate through only a subset of a Collection in C#? That is, I have a collection of a large number of objects (say, 1000), but I'd like to enumerate through only elements ...
32
votes
11
answers
22k
views
IEnumerable<T> as return type
Is there a problem with using IEnumerable<T> as a return type?
FxCop complains about returning List<T> (it advises returning Collection<T> instead).
Well, I've always been guided by ...
5
votes
4
answers
1k
views
What dotnet collection class's items can be enumerated in "addition order" and retrieved via a key?
I'm lead to believe that I cannot count on the order of items added to a dictionary for enumeration purposes.
Is there a class (generic if possible) to which items may be added with a key and which ...