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

147 questions
7
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
  • 119
  • 7
7
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
6
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
  • 1,206
  • 2
  • 15
  • 24
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
  • 31,198
  • 62
  • 198
  • 313
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
  • 654
  • 7
  • 20
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
  • 255
  • 1
  • 10
5
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
  • 382
  • 1
  • 8
  • 18
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
  • 17,363
  • 67
  • 204
  • 344
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
  • 652
  • 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
  • 12
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
  • 4
  • 15
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
  • 845
  • 2
  • 9
  • 24
3
votes
1 answer

toArray() vs. toArray(new Object[0])

I have an ArrayList called listtable. For some reason Clause[] whatever = listtable.toArray() gives an incompatible types error but Clause[] whatever = listtable.toArray(new Clause[0]) works just fine. Why is this so? What is the difference…
Elliot Gorokhovsky
  • 3,610
  • 2
  • 31
  • 56
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
  • 7,123
  • 7
  • 48
  • 90
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
  • 28,796
  • 74
  • 215
  • 331
1
2
3
9 10