toarray Questions

3

Solved

I'm looking for an easy way to clone off an IEnumerable<T> parameter for later reference. LINQ's ToArray extension method seems like a nice, concise way to do this. However, I'm not clear on...
Airminded asked 20/5, 2011 at 15:37

5

Solved

The following code (run in android) always gives me a ClassCastException in the 3rd line: final String[] v1 = i18nCategory.translation.get(id); final ArrayList<String> v2 = new ArrayList<...
Madelle asked 16/4, 2011 at 23:25

8

Solved

I was just looking at the method defined in the List interface: <T> T[] toArray(T[] a) , and I have a question. Why is it generic? Because of that fact, method is not complete type-safe. The ...
Woolgathering asked 14/3, 2013 at 23:33

2

This should be a pretty basic question, but I've been having a little trouble finding a definite answer. When you have an array of values and you use the .ToArray() method does it create a deep o...
Salas asked 30/4, 2012 at 16:49

1

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 arr...
Transposition asked 31/7, 2019 at 17:49

1

Solved

I am working on the site Codingbat, specifically this method in AP-1 public String[] wordsWithout(String[] words, String target) { ArrayList<String> al = new ArrayList<>(Arrays.asList...
Hazing asked 9/10, 2018 at 12:6

1

Solved

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: {...
Hungnam asked 6/12, 2017 at 18:43

2

Solved

I'm getting a List of object A, then I use Apache Commons Collection4 to transform the obtained List from having A instances to having B instances. listOfBs = (List<B>) CollectionUtil...
Phionna asked 7/4, 2014 at 12:57

2

Solved

I've been learning how to program with java and I haven't got any clear explanation about the difference of LinkedList's toArray(T[] a) and toArray() method. The second one simply returns all of th...
Gerhart asked 8/2, 2015 at 10:4

2

Solved

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 m...
Antihelix asked 7/2, 2014 at 1:37

1

Solved

I've noticed that database queries run faster when adding .ToArray() or .ToList() to queries. Is this because the data set is loaded into memory and all subsequent queries are done in-memory rather...
Thymol asked 28/1, 2014 at 14:46

2

Solved

I have a map private HashMap<Character, Integer> map; I want to convert it to array but when I do that/I get this: Entry<Character, Integer> t = map.entrySet().toArray(); **Ty...
Ejection asked 19/5, 2013 at 10:33

2

Solved

Possible Duplicate: How to convert List<Integer> 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 whic...
Naze asked 23/6, 2012 at 17:55

3

Solved

I've created a class called listItem and the following list: List<listItem> myList = new List<listItem>(); At some point in my code, I want to convert it to an array, thereby using: ...
Henpeck asked 3/4, 2012 at 9:16

3

Solved

I defined List<Integer> stack = new ArrayList<Integer>(); When I'm trying to convert it to an array in the following way: Integer[] array= stack.toArray(); I get this exception: E...
Vershen asked 2/9, 2011 at 9:52

5

Solved

I was just looking at the method defined in the List interface: Returns an array containing all of the elements in this list in the correct order; the runtime type of the returned array is that ...
Devotee asked 30/6, 2011 at 23:41

3

Before Java generics, Collection.toArray() had no way to know which type of array the developer expected (particularly for an empty collection). As I understand it, this was the main rationale behi...
Allopatric asked 30/5, 2011 at 7:38

5

Solved

In the code below, I needed to fetch an element, any element, from toSearch. I was unable to find a useful method on the Set interface definition to return just a single (random, but not required t...
Perfectionist asked 4/12, 2010 at 23:52

2

Solved

Right now, I have: public <T> T[] toArray(T[] old) { T[] arr = Arrays.copyOf(old, old.length + size()); int i = old.length; for(E obj : this) { arr[i] = old.getClass().getComponentType(...
Gunwale asked 24/10, 2010 at 23:1

5

Solved

I've got a List collection and I want to iterate over it in a multi threaded app. I need to protect it every time I iterate it since it could be changed and I don't want "collection was modified" e...
Slattery asked 27/6, 2010 at 21:2
1

© 2022 - 2024 — McMap. All rights reserved.