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
0
votes
2 answers

change a laravel collection format for dropdown

With Laravel, I generate my list of object like that: return Federation::lists('name','id'); So, this returns me [1 => 'elt1', 2 => 'elt2'] , etc What I need is transform it to: [{value => 1, text => 'elt1'},{value => 2, text => 'elt2'}] is it a…
Juliatzin
  • 18,455
  • 40
  • 166
  • 325
0
votes
1 answer

Cakephp 3 Cannot convert value to bool issue

I am execute flowing query . $query = $busdetails ->find('list',['keyField' => 'id','valueField' => 'bus_name']) ->where(['status'=>1,'is_approved'=>1]); pr($query->toArray()); It works fine if some results found but if no results…
Developer
  • 1
  • 1
  • 1
0
votes
3 answers

Trying to cast setInstance.toArray() to Integer[], no compile time error but there is run time error, why?

I'm experimenting with Java HashSet class and its toArray() method. Below is the code I have came up with. The compiler did not display any error but when I run the code, the IDE outputs the error message: Exception in thread "main"…
Thor
  • 9,638
  • 15
  • 62
  • 137
0
votes
1 answer

Fluent Iterable to array from a list that contain generic classes

I have the following class structure: abstract class Role; class Employee extends Role; class Student extends Role; class Employer extends Role; Also I have an enum in which I store the acceptable roles. public enum RoleEnum { EMPLOYEE…
0
votes
3 answers

Iterating through LinkedHashMap Values Isn't Ordered?

For a problem I'm designing in Java, I'm given a list of dates and winning lottery numbers. I'm supposed to do things with them, and spit them back out in order. I decided to choose a LinkedHashMap to solve it, the Date containing the date, and…
Luiserebii
  • 55
  • 2
  • 11
0
votes
4 answers

Split html row into string array

I have data in an html file, in a table:
001MC HammerCan't Touch This
002Tone LocFunky Cold Medina
003FunkdoobiestBow Wow…
fearofawhackplanet
  • 52,166
  • 53
  • 160
  • 253
0
votes
1 answer

Java Collection::toArray with subclasses

Is there a way to use the Collection::toArray(T[]) method when you only know the subtype of the collection? Take this example: void initList(Collection data) { JList aorb_jlist = new JList<>(); …
ryvantage
  • 13,064
  • 15
  • 63
  • 112
0
votes
0 answers

myIntList.toArray(new Integer[0]) throwing "incompatible types" error

I have an ArrayList that I need converted back into an int[]. I have been trying to use the T[] toArray(T[] a) method inherited from the List interface. I've looked up several examples, and it seems I'm doing it right. Can someone tell me why I'm…
user3376587
  • 134
  • 2
  • 12
0
votes
3 answers

ArrayList cannot be cast to java.util.ArrayList, toArray returns nothing

I am trying to write a hierarchal block that puts elements into an ArrayList, all apart of a larger ArrayList. What the block does is take an existing input of text, and adds every line of text into elements of an ArrayList. Each Line is then…
0
votes
5 answers

Java Object Array item to String Array

Say I have the following: Class myclass { public string stra ="", strb = "" myclass(String a, String b){stra=a;strb=b} } //then in the app I want to do: myclass myclassinst1 = new myclass("blah","xxxx"); myclass myclassinst2 = new…
DGoulston
  • 3
  • 4
0
votes
2 answers

Difference between printing array returned from toarray() method using enhanced for loop and traditional for loop

I have this code, class Test { public static void main(String args[]) { ArrayList al=new ArrayList<>(); al.add(1); al.add(2); al.add(3); Integer a[]=new Integer[2]; al.toArray(a); …
Gpar
  • 181
  • 1
  • 1
  • 7
0
votes
3 answers

Return values from SQL Server to C# convert ToArray?

I am working on an assignment at the moment, trying to get values from a SQL Server database and storing them in an array. My connection is fine, but I am having trouble putting the returned values into an array. Here is what I've got, have changed…
0
votes
2 answers

Doctrine toarray does not convert relations

I followed doctrine documnetation to get started. Here is the documentation. My code is $User = Doctrine_Core::getTable("User")->find(1); when I access relations by $User->Phonenumbers, it works. When I convert User object to array by using…
Moon
  • 22,195
  • 68
  • 188
  • 269
0
votes
1 answer

.toArray from ArrayList to Array convertion, data type confusion

I have confused myself with typecasting with this problem. I have an ArrayList of chars that I want to convert into a String—an array of chars. So it goes something like this: ArrayList message = new ArrayList(); String…
Tobias Tovedal
  • 731
  • 2
  • 8
  • 14
0
votes
1 answer

Generics: Array of type expected

I have the following code: public class DEF implements Set { private EnumSet xyz=EnumSet.noneOf(ABC.class); @Override public T[] toArray(T[] a) { return xyz.toArray(a); } } Which gives me the following…
JohnyTex
  • 3,323
  • 5
  • 29
  • 52