collections

How to build this Java Collection from a ResultSet

早过忘川 提交于 2019-12-14 03:11:02
问题 I have data from a ResultSet that contains three fields: DataType, Data, DataValue. I want to build a Java Collection, and next build the JSON encode. This is the output when I try to print: System.out.println(resultSet.getString("DATATYPE") + " --> " + resultSet.getString("DATA") + " --> " + resultSet.getString("DATAVALUE")); Output: Address --> Test --> JHGJHGJKG Address --> City--> Some city Address --> State --> Some state Address --> Downtown --> Some downtown Address --> Telephone -->

Arraylist of objects - smallest value

天涯浪子 提交于 2019-12-14 02:36:13
问题 I have an arraylist of objects, and the objects have "double" values. I need to print out all the objects, and have the object with the highest value printed first, and the object with the lowest value last. I have also tried to use Collections to sort the arraylist and then print, but I can't seem to get it to work. My arraylist is: ArrayList<Transition> transitions = new ArrayList<Transition>(); When i tried to used Collections i used: Object minValue = Collections.min(transitions); Hope

Semantic of startsWith on Arrays

十年热恋 提交于 2019-12-14 02:12:29
问题 I was caught off guard by this expression: val words = strings.map(s => s.split(“,”)) // split CSV data val nonHashWords = words.filter(word => word.startsWith(“#”)) This construction is faulty, as words is a Seq[Array[String]] instead of the intented Seq[String] . I didn’t expect that Array would have a startsWith method, so I played a bit with it to understand its semantics. I naturally expected this to be true: Array(“hello”, “world”).startsWith(“hello”) Here’s the rest of my exploration

NodeJS + Mongo native – check if collection exists before query

↘锁芯ラ 提交于 2019-12-14 01:41:39
问题 I've got a function, trying to get a specific value from settings collection in MongoDB. The marker for settings object, containing settings values, in settings collection is {'settings':'settings'}. The schema is: collection:setting |--object |--{'settings':'settings'} |--{'valueA':'valueA'} |--... The problem is when I first time query settings object, the collection 'settings' simply does not exists. So, exports.getInstruments = function (callback) { db.collection("settings", function

A concurrent collection that maintains insertion order [closed]

冷暖自知 提交于 2019-12-14 01:19:23
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I'm looking for a concurrent list that can maintain the insertion order. Does anyone have some good recommendation ? I look at some from guava e.g. SetFromMap, but they are deprecated in the new version. Thank you. 回答1: If you have mostly read operations, very few write operations and you don't have too much

HashMap Not Calling Object.equals?

若如初见. 提交于 2019-12-14 01:05:24
问题 I wrote a class that overrides the equals(Object) method in class Object to compare objects of the class type to other objects of a class type using the object's instance values. When I put an instance of the object in a HashMap as the key, and then call get(Object) on the map with a new but identical object as the key, it returns null. I've tried passing a new, identical object to the equals method and it returns true, so the problem isn't my comparison code. From what I've gathered through

Why there is no ArrayList(T[] t) constructor?

让人想犯罪 __ 提交于 2019-12-14 00:29:49
问题 It is very common to initialize list by array of objects in such way: Foo[] objs = ...; ArrayList<Foo> list = new ArrayList<Foo>(Arrays.asList(objs)); I wonder, is there any reason why desiners of ArrayList didn't include constructor with array as parameter, so that it could be initialized like that: ArrayList<Foo> list = new ArrayList<Foo>(objs); May be it violates some principles, thread-safety or something else? 回答1: I don't know why it's not in the standard library, but Guava's Lists

Is there a dictionary like collection that can use a property of its value as the key?

旧街凉风 提交于 2019-12-14 00:22:49
问题 Instead of using Dictionary<TKey,TValue> I want some type of collection class that can use a property of the value as the key, is there something like this? 回答1: Yes, there is - System.Collections.ObjectModel.KeyedCollection<TKey, TValue>. That's abstract, and there are no concrete derived classes in the framework as far as I can see, but all you need to implement is GetKeyForItem as far as I can see. For example, you could do this with a delegate: public class DelegatingKeyedCollection<TKey,

Convert String into ArrayList<MyClass>

耗尽温柔 提交于 2019-12-14 00:13:18
问题 I want to convert a String myString like that: [ ["cd",5,6,7], ["rtt",55,33,12], ["by65",87,87,12] ] into an ArrayList<CustomClass> Where CustomClass have constructor : public CustomClass (String name, int num1, int num2, int num3) I tried first to create ArrayList of Strings : List<String> List = new ArrayList<String>(Arrays.asList(myString.split("["))); Didn't worked for me... How can I get something like that: List - {CustomClass,CustomClass,CustomClass,CustomClass} first CustomClass =

Creating an own collection class in c# [closed]

怎甘沉沦 提交于 2019-12-13 23:52:26
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I am a new c# developer and im on the learning curve on c#. Now, i have an very small project where I should write my own generic list class for storing data. Im not allowed to use any of the .NET collection