collections

Search a java.util.List starting at a specific index

穿精又带淫゛_ 提交于 2021-01-28 02:20:44
问题 Is there a built-in method to search a java.util.List specifying the first item to start the search from? Like you can do with Strings I know I can easily implement something on my own, but I'd rather not reinvent the wheel if Java or http://commons.apache.org/collections/api-release/org/apache/commons/collections/package-summary.html already has it. I'm not asking how to implement this, I'm asking whether something is already available A lot of the suggestions here were buggy. If anybody

Search a java.util.List starting at a specific index

十年热恋 提交于 2021-01-27 22:31:25
问题 Is there a built-in method to search a java.util.List specifying the first item to start the search from? Like you can do with Strings I know I can easily implement something on my own, but I'd rather not reinvent the wheel if Java or http://commons.apache.org/collections/api-release/org/apache/commons/collections/package-summary.html already has it. I'm not asking how to implement this, I'm asking whether something is already available A lot of the suggestions here were buggy. If anybody

Change sort order of strings includes with a special character (e.g. “_”)

强颜欢笑 提交于 2021-01-27 14:01:49
问题 A PHP script outputs a list of e-mail addresses in descending order like following: _abc_@testmail.com _abc45_@testmail.com _abc2_@testmail.com ypaux2aux@yahoo.com yaremchuk56@testmail.com vasillevn@hotmail.com ugur@hotmail.com twes@gmail.com tukaux@yahoo.com ttsetaux1@yahoo.com tra@testmail.com In Java, I'm creating an ArrayList from these e-mails, then sorting in descending order. The result is different: ypaux2aux@yahoo.com yaremchuk56@testmail.com vasillevn@hotmail.com ugur@hotmail.com

ES6 group array objects by field type

点点圈 提交于 2021-01-27 06:22:27
问题 Is there a terse es6 functional way to group items by type in that it's immutable? accounts.json [ {"account": {"name": "Bob's credit", "type": "credit", "id": "1"}}, {"account": {"name": "savings", "type": "savings", "id": "2"}}, {"account": {"name": "vacation savings", "type": "savings", "id": "3"}}, {"account": {"name": "son's savings", "type": "savings", "id": "4"}, {"account": {"name": "wife's credit card", "type": "savings", "id": "5"} ] Expected [ {"savings": [ {"account": {"name":

Checking number of elements in Python's `Counter`

半腔热情 提交于 2021-01-27 05:43:09
问题 Python 2.7/3.1 introduced the awesome collections.Counter . My question: How do I count how many "element appearances" a counter has? I want this: len(list(counter.elements())) But shorter. 回答1: sum(counter.itervalues()) 来源: https://stackoverflow.com/questions/5506359/checking-number-of-elements-in-pythons-counter

How to invoke System.Linq.Enumerable.Count<> on IEnumerable<T> using Reflection?

泪湿孤枕 提交于 2021-01-27 04:22:16
问题 I have a bunch of IEnumerable Collections which exact number and types is subject of frequent changes (due to automatic code generation). It looks something like this: public class MyCollections { public System.Collections.Generic.IEnumerable<SomeType> SomeTypeCollection; public System.Collections.Generic.IEnumerable<OtherType> OtherTypeCollection; ... At runtime i want to determine each Type and it's count without having to rewrite the code after every code generation. So i am looking for a

The best way to check if List<String[]> contains a String[] [duplicate]

ぐ巨炮叔叔 提交于 2021-01-27 03:55:41
问题 This question already has answers here : Java, return if trimmed String in List contains String (7 answers) Closed 4 years ago . I have a List declared as: List<String[]> arrayList = new ArrayList<>(); This List contains multiple arrays of String s. I need to check if a String[] which I have is contained in this ArrayList<String[]> . I am currently iterating through the ArrayList and comparing each String[] with the one I am searching for: for(String[] array: arrayList){ if(Arrays.equals

The best way to check if List<String[]> contains a String[] [duplicate]

微笑、不失礼 提交于 2021-01-27 03:55:15
问题 This question already has answers here : Java, return if trimmed String in List contains String (7 answers) Closed 4 years ago . I have a List declared as: List<String[]> arrayList = new ArrayList<>(); This List contains multiple arrays of String s. I need to check if a String[] which I have is contained in this ArrayList<String[]> . I am currently iterating through the ArrayList and comparing each String[] with the one I am searching for: for(String[] array: arrayList){ if(Arrays.equals

Java: Sorting a queue

此生再无相见时 提交于 2021-01-23 12:37:26
问题 I'm making a wrapper to queue type, but each time I add element, I want to sort everything inside. Mostly it will be Integer . I'm not too familiar with Collections framework, is there any simple solution ? public class Round<Type> { private Queue<Type> qe; public Round(){ this.qe = new LinkedList<Type>(); } public void push(Type p){ this.qe.offer(p); //Collections.sort(this.qe); Here I want to sort this } public Type pop(){ return this.qe.poll(); } } 回答1: Are you sure that is what you want?

Java: Sorting a queue

一曲冷凌霜 提交于 2021-01-23 12:34:14
问题 I'm making a wrapper to queue type, but each time I add element, I want to sort everything inside. Mostly it will be Integer . I'm not too familiar with Collections framework, is there any simple solution ? public class Round<Type> { private Queue<Type> qe; public Round(){ this.qe = new LinkedList<Type>(); } public void push(Type p){ this.qe.offer(p); //Collections.sort(this.qe); Here I want to sort this } public Type pop(){ return this.qe.poll(); } } 回答1: Are you sure that is what you want?