collections

C# ValueTuple of any size

可紊 提交于 2020-07-06 18:43:50
问题 Is it possible to write a C# method that accepts a value tuple with any number of items of the same type and converts them into a list? Edit 2/6/2019 I accepted the Provided answer as the correct one. I wanted to also provide a solution that uses a base class that is not an interface, becuase I am trying to write a conversion operator and user defined conversions from an interface are not allowed. public static class TupleExtensions { public static IEnumerable<object> Enumerate(this ValueType

How can I create a list with N objects?

泪湿孤枕 提交于 2020-07-02 07:25:41
问题 I am trying to create a list of objects with n elements. I am trying to do this in the most java 8 way as possible. Something similar to the question asked for c# here : Creating N objects and adding them to a list Something like this: List <Objects> getList(int numOfElements) { } 回答1: If I got your question right: List <Object> getList(int numOfElements){ return IntStream.range(0, numOfElements) .mapToObj(Object::new) // or x -> new Object(x).. or any other constructor .collect(Collectors

How can I create a list with N objects?

强颜欢笑 提交于 2020-07-02 07:24:29
问题 I am trying to create a list of objects with n elements. I am trying to do this in the most java 8 way as possible. Something similar to the question asked for c# here : Creating N objects and adding them to a list Something like this: List <Objects> getList(int numOfElements) { } 回答1: If I got your question right: List <Object> getList(int numOfElements){ return IntStream.range(0, numOfElements) .mapToObj(Object::new) // or x -> new Object(x).. or any other constructor .collect(Collectors

Sorting ArrayList in Koltin

北城以北 提交于 2020-06-29 04:40:06
问题 I've have a ArrayList of ArrayList what I want to achive is , to sort them in decending order (based on Highest to lowest List size ) to get largest first and onwards. I did same thing in java using Collections.It worked perfectly fine there but now I'm unable to achieve this in Koltin i'm getting ERROR. Consider I've have class Foo() private var allHistoryList: ArrayList<ArrayList<Foo>> = arrayListOf() /** * Sorting array of array list to get Biggest to smallest array List based of size */

Java enhanced for loop (for each loop) throws Exception

做~自己de王妃 提交于 2020-06-29 03:46:46
问题 I was recommended to use a List<JLabel> list = new ArrayList<class> to collect and later remove a number of unspecific JLabel images from my JPanel private List<JLabel> cardImages = new ArrayList<JLabel>(); public void addCardImage(BufferedImage img, boolean playerCard) { JLabel imgLabel = new JLabel(); ImageIcon icon; icon = new ImageIcon(img); imgLabel.setIcon(icon); cardImages.add(imgLabel); if (playerCard) pCardPanel.add(imgLabel); else dCardPanel.add(imgLabel); display.pack(); } private

Delete element from Varray Oracle

蓝咒 提交于 2020-06-28 06:21:11
问题 I have created Varray as : CREATE TYPE mytype IS VARRAY (4) OF VARCHAR2(50); / Then Created table as : CREATE TABLE tbl( a NUMBER, b VARCHAR2(30), c mytype); / Inserted values as : INSERT INTO tbl(a, b, c) VALUES (1,'Eng', mytype('qq','rr', 'yy', 'ttt')); How I can delete only the element 'ttt'?? Thanks !! 回答1: The Oracle documentation states that this is not possible directly via SQL: 5.3.2.3 Performing Atomical Changes on VARRAYs and Nested Tables You can make atomical changes to nested

Java - Load CSV to Complex Nested Map with POJO

最后都变了- 提交于 2020-06-27 17:33:06
问题 I have CSV file which is in the form as below student, year, subject, score1, score2, score3 Alex, 2010, Math, 23, 56, 43 Alex, 2011, Science, 45, 32, 45 Matt, 2009, Art, 34, 56, 75 Matt, 2010, Math, 43, 54, 54 I'm trying to find an optimal solution to read the CSV file and load it to a map for lookup purposes i.e. Map<String, Map<String, List<SubjectScore>>> . The first string key is for student, the next string key is for year. class SubjectScore { private String subject; private int score1

Is there a way to call a C# method requiring an IEnumerable<T> with a single value? …with benchmarking [duplicate]

亡梦爱人 提交于 2020-06-26 12:24:27
问题 This question already has answers here : Passing a single item as IEnumerable<T> (18 answers) Closed 15 days ago . I'm just wondering if I'm missing out on some syntactic sugar or micro-optimization... If I'm calling a method requiring an IEnumerable of values but I only have a single value, then I put that single value in an array. for example: var x = 1.23; SquareAllTheNumbers(new[] { x }); private void SquareAllTheNumbers(IEnumerable<double> values) { foreach (var value in values) {

(Un)boxing primitive arrays in Java

雨燕双飞 提交于 2020-06-25 09:30:51
问题 in the Android Java world, is there a straighforward (ideally one-call) way to convert an array of int to an ArrayList<Integer> and back? Calling toArray() on the ArrayList returns an array of Integer - not quite what I want. I can easily do that by hand with a loop (already did, in fact). I'm wondering if the library/language supports the same. EDIT: thanks all, I already wrote my own boxer and unboxer. I'm just surprised the language/RTL designers didn't think of it themselves, especially

Sorting a collection of objects in VBA

吃可爱长大的小学妹 提交于 2020-06-25 04:38:23
问题 I'm trying to write a function that would sort a collection of objects. Since the objects are all of the same type (the same user-defined class), their property set is the same. Is it possible to discover the object's properties (through code) so as to put the collection in a bi-dimensional array, each row being for an object, each column for one of its property? Another solution would be to copy each object from the collection to an array of objects, and sort them by one of their property,