collections

Find some values in a mongodb collection?

安稳与你 提交于 2019-12-20 01:37:20
问题 Im trying to read a (mongo)userdatabase with java. On the tutorial page I saw how to read the whole collection. I can do something like that: DBCursor cursor = col.find(); while (cursor.hasNext()) { System.out.println(cursor.next()); } Now if I have a collection with users := name, age, password (...) and whatever. Now I would like to find a name with a password. For example for a login process. Lets say I have two strings: String n and p. If there is a user.equals(n) and a password.equals(p)

Why is ForEach Method only on the List<T> collection? [duplicate]

半世苍凉 提交于 2019-12-19 19:52:52
问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: Why is there not a ForEach extension method on the IEnumerable interface? First, let me specify I am refering to the List<T> method and not the C# keyword. What would be Microsoft's reasoning for having the Foreach method on the List<T> collection but no other collection/enumerable type, specifically IEnumerable<T> ? I just discovered this method the other day, and found it to be very nice syntax for replacing

How can I define a property type as being a list (list, set, array, collection) of string in my YAML Swagger definition

扶醉桌前 提交于 2019-12-19 17:41:01
问题 I am writing a swagger definition file for an API. The API is a for a GET request /path/to/my/api: get: summary: My Custom API description: | Gets a List of FooBar IDs produces: - application/json tags: - FooBar responses: "200": description: successful operation schema: $ref: "#/definitions/MyCustomType" ... MyCustomType: type: object properties: myCustomObject type: ??? # list of string? 回答1: For a list of strings, you can describe as follows: type: array items: type: string Ref: https:/

What is faster in finding element with property of maximum value

喜夏-厌秋 提交于 2019-12-19 17:39:40
问题 Commonly, to find element with property of max value I do like this var itemWithMaxPropValue = collection.OrderByDescending(x => x.Property).First(); But is it good way from performance point of view? Maybe I should do something like this? var maxValOfProperty = collection.Max(x => x.Property); var itemWithMaxPropValue = collection .Where(x => x.Property == maxValueOfProperty).First(); 回答1: Both solutions are not very efficient. First solution involves sorting whole collection. Second

Java : Priority Queue

梦想的初衷 提交于 2019-12-19 17:38:25
问题 I have a java program which goes like this public class PriorityQueueExample { public static void main(String[] args) { PriorityQueue<Integer> pq = new PriorityQueue<Integer>(); pq.add(10); pq.add(1); pq.add(9); pq.add(2); pq.add(8); pq.add(3); pq.add(7); pq.add(4); pq.add(6); pq.add(5); System.out.println(pq); } } My Question is why does not the priority queue sort them. As per the java specs it implements comparable and maintains the sorting order(natural sorting) My output of the program

Is this java Object eligible for garbage collection in List

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 17:12:54
问题 What I am asking might be a stupid question so please pardon me for that. So it goes like this : List<Boss> bossList = new ArrayList<Boss>(); Boss b = null; for(Employee e : List<Employee> myList){ b = new Boss(); b.setEmployee(e); bossList.add(b); b = null; } So in above scenario, I am creating lot of Boss objects and then de-referencing them(I know I don't need to write "b = null", but i did it for clarity of my question). In normal scenario, I would have marked them to garbage collection,

Is this java Object eligible for garbage collection in List

倾然丶 夕夏残阳落幕 提交于 2019-12-19 17:12:11
问题 What I am asking might be a stupid question so please pardon me for that. So it goes like this : List<Boss> bossList = new ArrayList<Boss>(); Boss b = null; for(Employee e : List<Employee> myList){ b = new Boss(); b.setEmployee(e); bossList.add(b); b = null; } So in above scenario, I am creating lot of Boss objects and then de-referencing them(I know I don't need to write "b = null", but i did it for clarity of my question). In normal scenario, I would have marked them to garbage collection,

How to pass a kotlin collection as varagrs?

女生的网名这么多〃 提交于 2019-12-19 16:59:12
问题 At first glance it is needed just convert collection to array and pass it to method but this does not work: val toTypedArray = Arrays.asList("a", "b").toTypedArray() Paths.get("", toTypedArray) // <- compilation error here No workarounds??? 回答1: An Array can be passed as an vararg argument by prepending * to it: Paths.get("", *toTypedArray) It’s called spread operator , as I already described in another question here. An instance of List can be converted to vararg as follows: val listAsArr =

WPF/MVVM: Delegating a domain Model collection to a ViewModel

耗尽温柔 提交于 2019-12-19 11:43:27
问题 A domain model collection (normally a List or IEnumerable) is delegated to a ViewModel. Thats means my CustomerViewModel has a order collection of type List or IEnumerable. No change in the list is recognized by the bound control. But with ObservableCollection it is. This is a problem in the MVVM design pattern. How do you cope with it? UPDATE : Sample of how I do it: public class SchoolclassViewModel : ViewModelBase { private Schoolclass _schoolclass; private ObservableCollection

What sorting algorithm used while overriding compare method of comparator interface?

帅比萌擦擦* 提交于 2019-12-19 11:42:30
问题 Collections.sort(ar, new Comparator<Intervals>() { @Override public int compare(Intervals o1, Intervals o2) { return (Integer.valueOf(o1.getEnd())) .compareTo(Integer.valueOf(o2.getEnd())); } }); Hi all, I have the above code in java. Here, ar is a list and Intervals is a class with 2 integer variables : Start and End. I wanted to know what sorting algorithm is followed when we override the compare method of Comparator interface as above. I know, by default Collections.sort() and Arrays.sort(