collections

C# equivalent for java arraylist supporting get, set and remove certain Index

一世执手 提交于 2019-12-30 04:01:05
问题 I am a Java programmer, I have used a Java ArrayList before and now I want to have something like that in C#. Some of options I need are in this Java code: String[] strs = new String[]{"str1" , "str2" , "str3" , "str4"}; ArrayList arrayList = new ArrayList(35); arrayList.add(strs[0]); arrayList.add(strs[1]); arrayList.remove(0); arrayList.set(0, strs[2]); String s = (String) arrayList.get(1); I used C# ArrayList and LinkedList , but they don't have these simple options that I need. Is there

Are JavaScript Map Objects Indexed to Optimize map.get? [duplicate]

假如想象 提交于 2019-12-30 03:26:08
问题 This question already has answers here : es6 Map and Set complexity, v8 implementation (2 answers) Closed 4 years ago . Behind the scenes, in V8, are JavaScript-Map-object's keys indexed in some manner that optimizes the map.get method? Or does map.get() simply just loop through the entire map until it discovers a key match? I'm interested in the efficiency of map.get on larger mappings of 500,000+ key/value pairs. I have this many mappings that I'd like to just cache in RAM, instead of

Any way to stream a map like “(k,v)” instead of working with (entry)?

99封情书 提交于 2019-12-30 03:05:11
问题 Basically I look for a way to avoid working with entry -> entry.getValue and entry -> entry.getKey similar to what Map.forEach() does. If only I could get a way to work as map.stream().filter((k,v) -> ) ... and so on It seems the interface is called BiConsumer. Perhaps with a converter to BiConsumer or a Stream.generate() someway 回答1: Since this is a repeating question, I will throw a full solution into the ring. It’s a PairStream type that is by default a simple wrapper around an ordinary

How does ObservableCollection<T>.Move(int,int) work?

Deadly 提交于 2019-12-30 01:51:09
问题 I can't seem to figure this one out by reading the documentation for ObservableCollection.Move(int oldIndex, int newIndex) on MSDN: oldIndex Type: System.Int32 The zero-based index specifying the location of the item to be moved. newIndex Type: System.Int32 The zero-based index specifying the new location of the item. I don't understand how it works. What happens to the item with newIndex ? My assumption is that the index of each item with index >= newIndex is decremented. Is that assumption

magento orders list query

前提是你 提交于 2019-12-30 01:38:09
问题 I want to select the list of all orders in Magento. This is required for me to show the list of all the orders from magento in another PHP application presently I'm working on. Also can some one write me the code using the Magento conventions such as Mage:: Im using Magento 1.4.2 version. Thanks, Mark 回答1: This code uses the "Magento way" and accesses the data through the Model layer which insulates you from changes in the table structure (e.g. flat vs EAV). Create a new PHP file containing

Library method to partition a collection by a predicate

别说谁变了你拦得住时间么 提交于 2019-12-30 01:37:11
问题 I have a collection of objects that I would like to partition into two collections, one of which passes a predicate and one of which fails a predicate. I was hoping there would be a Guava method to do this, but the closest they come is filter, which doesn't give me the other collection. I would image the signature of the method would be something like this: public static <E> Pair<Collection<E>, Collection<E>> partition(Collection<E> source, Predicate<? super E> predicate) I realize this is

Merge Map<String, List<String> Java 8 Stream

独自空忆成欢 提交于 2019-12-30 01:07:08
问题 I would like to merge two Map with JAVA 8 Stream: Map<String, List<String>> mapGlobal = new HashMap<String, List<String>>(); Map<String, List<String>> mapAdded = new HashMap<String, List<String>>(); I try to use this implementation: mapGlobal = Stream.of(mapGlobal, mapAdded) .flatMap(m -> m.entrySet().stream()) .collect(Collectors.groupingBy(Map.Entry::getKey, Collectors.mapping(Map.Entry::getValue, Collectors.toList()) )); However, this implementation only create a result like: Map<String,

C# getting all colors from Color

﹥>﹥吖頭↗ 提交于 2019-12-30 00:59:10
问题 I want to make a ComboBox filled with all the colors from System.Drawing.Color But I can't seem to collect all the colors from that collection I've already tried using a foreach to do the job like this: foreach (Color clr in Color) { } But all I get is an error. So how can I loop trough all the colors? Any help will be appreciated. 回答1: You could take color from KnownColor KnownColor[] colors = Enum.GetValues(typeof(KnownColor)); foreach(KnownColor knowColor in colors) { Color color = Color

Remove object from has_many but don't delete the original record in Rails?

笑着哭i 提交于 2019-12-30 00:51:07
问题 I have this: Post.paragraphs << new_paragraph And I need to remove paragraph by id = 3, so the following deletes the record completely: Post.paragraphs.find(paragraph_id).destroy # or Post.paragraphs.find(paragraph_id).delete I just need to remove a paragraph from has_many association. I tried to use delete and destroy . Both methods completely delete records from the associated tables. How can I just remove them from the "container"? 回答1: You should not use the delete method on the Paragraph

How to find duplicates in an ArrayList<Object>?

十年热恋 提交于 2019-12-30 00:03:44
问题 This is a pretty common question, but I could not find this part: Say I have this array list: List<MyDataClass> arrayList = new List<MyDataClass>; MyDataClass{ String name; String age; } Now, I need to find duplicates on the basis of age in MyDataClass and remove them. How is it possible using something like HashSet as described here? I guess, we will need to overwrite equals in MyDataClass? But, what if I do not have the luxury of doing that? And How does HashSet actually internally find and