Questions tagged [toarray]

toarray, to convert from arraylist to array this method can be used. Being language specific for e.g. in Java its its available with ArrayList and in C# its used with List. Use this tag for toarray related questions.

toArray() Returns an array containing all of the elements in this list in the correct order.

Resource

136 questions
6
votes
1 answer

Why do keys change when children are used with React.Children.toArray?

If I have a react component with children and I call React.Children.toArray on these children, why does the objects in the array have keys that are prepended with .$ var Child = React.createClass({ render: function() { …
SubHero
  • 99
  • 6
6
votes
2 answers

Why does LINQ GroupBy produce different results when preceded by ToArray()?

I'm pulling some data from SQL using Entity Framework. I've written some code that looks like the snippet below. Note that Something is a varchar value from the database. Furthermore, I think it may be relevant that every value in Something…
Vivian River
  • 28,530
  • 54
  • 179
  • 298
5
votes
1 answer

Which toArray conversion pattern is best to use?

I had the following piece of code that IntelliJ suggested I should change: String[] normalizedNames = rawToNormalized.values().stream().toArray(String[]::new); into String[] normalizedAliases = rawToNormalized.values().toArray(new…
QuirkyBit
  • 507
  • 3
  • 17
5
votes
1 answer

Why is there no toArray(Class)?

Why is there no toArray variant in List which only accepts a type, for example: Foo[] array = list.toArray(Foo.class); // or Foo[] array = list.toArray(Foo[].class); I have seen // existing array Foo[] array = list.toArray(array); // Fake…
james_t
  • 236
  • 1
  • 8
5
votes
2 answers

How to convert hashmap to Array of entries

I have a map private HashMap map; I want to convert it to array but when I do that/I get this: Entry t = map.entrySet().toArray(); **Type mismatch: cannot convert from Object[] to…
Yoda
  • 15,011
  • 59
  • 173
  • 291
5
votes
2 answers

list.toArray(T[] a), what if the "T" is a "runtime type"?

list.toArray(T[] a), what if the T is a "runtime type"? "List" interface in Java, the method: T[] toArray(T[] a) OK, it's a quite old question, usually we use it like that: String[] array = list.toArray(new String[0]); String[] array =…
watchzerg
  • 632
  • 1
  • 7
  • 12
5
votes
1 answer

toArray in Scala 2.10 Milestone

The following Scala code works fine in Scala 2.9, but it generates compiler error in Scala 2.10 Milestone. Can anybody give me a hint how to create an ArrayTag: type Lit = Array[Int] var list = List[Lit].empty list ::= Array(1,2,3) list ::=…
Tianyi Liang
  • 250
  • 2
  • 11
4
votes
4 answers

Why is toArray implemented like this in java?

As I see the source code of: java.util.AbstractCollection.toArray(), it is implemented like this: public Object[] toArray() { // Estimate size of array; be prepared to see more or fewer elements Object[] r = new Object[size()]; …
scugxl
  • 317
  • 3
  • 14
4
votes
1 answer

Converting Json into a DTO array

I have an interesting JSON parsing problem, at least to me since I am doing this for the first time. I have the following sample JSON and I want to map it to equivalent DTOs: { "modules": [ { "name":"module1", …
sgsi
  • 372
  • 1
  • 7
  • 18
4
votes
2 answers

Conversion Object[] to int[] error

Possible Duplicate: How to convert List to int[] in Java? I have an ArrayList and when I try to convert it into an Array of Integer because I need to do operations which concerns integer, I get this error : incompatible types …
user1079425
3
votes
1 answer

Laravel Scout toSearchableArray() not being called?

I have working search functionality on one of my models (Recipe) using Laravel Scout and TNTSearch: teamtnt/laravel-scout-tntsearch-driver. I want to add the same search functionality to a different model (Ingredient). I'm attempting to get search…
Friso Hoekstra
  • 635
  • 1
  • 6
  • 23
3
votes
1 answer

MongoDB toArray performance

I'm trying to build a category tree from a term collection in Mongo/Node, but first I select all tree elements using $in: console.time('termsCol.find'); var terms = await termsCol.find({term_id: {'$in':…
steakoverflow
  • 763
  • 2
  • 9
  • 20
3
votes
1 answer

Dictionary .Values and .Keys to array (in same order)

Is there an elegant way to get a dictionary's keys and values in the same order? I am worried that if I use dict.Values.ToArray() and dict.Keys.ToArray() (or dict.Select(obj => obj.Key) and dict.Select(obj => obj.Value)), that they won't be in the…
user
  • 6,723
  • 6
  • 41
  • 86
3
votes
2 answers

Create generic array for toArray method

I have this following method: public static T[] getKeysForValue(Map map,U value){ if(map == null || map.isEmpty()) { return null; } Set keys = new HashSet(); for (Map.Entry entry : map.entrySet()) { …
Tapas Bose
  • 25,780
  • 71
  • 202
  • 317
2
votes
2 answers

2D ArrayList to a normal array java

Basically, I am creating a dynamic 2d ArrayList. private ArrayList myArray; This code below is done in loop. A few random strings of the "same length" is given to store the all the characters in array. while (body) char[] temp =…
1
2
3
9 10