TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dinesh Santhalingam
NA
737
371.2k
How to load Arraylist to Array
Jan 5 2017 4:29 AM
I have a Array list.I want to convert this into separate array.
My Array list name is [obj];
obj={ {[A],[B]} ,
{[C],[D]},
{[E],[F]} }
Now I want to convert it to separate Array.
array x1= {[A],[B]};
array x2= {[C],[D]};
array x3= {[E],[F]};
What am tried:
for (var
i
=
0
; i
<
obj.length
; i++) {
X
=
obj
[i];
}
Please help me to achieve this?
Reply
Answers (
9
)
5
Suthish Nair
0
30.5k
7.2m
Jan 5 2017 4:59 AM
string[] array will have the collection... you can use array[0]... array[i]
4
Khaja Moizuddin
161
11.5k
1.9m
Jan 5 2017 11:59 AM
Try this https://msdn.microsoft.com/en-us/library/fcyyh2hb(v=vs.110).aspx https://www.dotnetperls.com/convert-arraylist-array http://stackoverflow.com/questions/8924869/how-to-convert-arraylist-into-string-arraystring-in-c-sharp hope this helps
4
Bikesh Srivastava
81
23.9k
3.5m
Jan 5 2017 11:50 AM
i think best option is use foreach loop and store one by one in separte array.
4
Dinesh Santhalingam
0
737
371.2k
Jan 5 2017 4:56 AM
Thanks for your guidance.@
Chetan Ranpariya
4
Chetan Ranpariya
0
1.1k
240
Jan 5 2017 4:49 AM
Dinesh,
You can not generate the variable names at runtime like X1, X2 and so on.
Here you have obj, which is Array of Arrays.
Instead of creating another array out of it why don't you use it directly where ever you want to use it? As following.
for
(
var
i = 0; i < obj.length; i++) {
var
arr = obj[1];
//do looping with arr to access its values
for
(
var
j = 0; j< arr.length;j++)
{
//use arr[i] to do whaterver you want...
}
}
I hope this will help you.
This is a simple logic.
Thanks and regards,
Chetan Ranpariya
[No programming language is helpful if logic is not clear]
4
Dinesh Santhalingam
0
737
371.2k
Jan 5 2017 4:41 AM
Can you please explain more about what the function doing? @
Suthish Nair
4
Dinesh Santhalingam
0
737
371.2k
Jan 5 2017 4:39 AM
The last array in array list only append to the X.I want to create X1,X2,X3 arrays and append that three arrays from Arraylist @
Chetan Ranpariya
4
Suthish Nair
0
30.5k
7.2m
Jan 5 2017 4:37 AM
string
[] array = obj.ToArray(
typeof
(
string
))
as
string
[];
or
string
[]
array
= (
string
[])
obj
.ToArray(
typeof
(
string
));
4
Chetan Ranpariya
0
1.1k
240
Jan 5 2017 4:36 AM
Hi Dinesh,
What problem did you face with your approach?
Did you get any error or exception?
Thanks and regards,
Chetan Ranpariya
load object to an array.
How to draw a Multiple line chart using Jqplot?