convert or copy an array of struct to an array (or something I can use)

I have this
 Mystruct array[] = new array[100];
System.out.print (array[i].ThirdElementOfMyStruct); // it works

but I  would copy array[i].ThirdElements into an array
What can I do ?


Who is Participating?
imladrisConnect With a Mentor Commented:
Again, no apparent way of doing it in a single operation. To get it into an array, would then be something like:

int eoarray[]=new int[100];
for(i=0; i<100; ++i)

To find a serial number you would check each element:

int i;
for(i=0; i<dda.length; ++i)
{   if(dda[i].snr==67343)break;
if(i<dda.length) // serial number found

It sounds like you have a structure (Mystruct), which contains a bunch of fields. One of the fields is named ThirdElementOfMyStruct. Your description doesn't specify what the type of the field ThirdElementOfMyStruct is. So I'll assume that it is some kind of object (not a primitive like int) for the moment.

If that is correct, then there is no way of doing this in a single operation. It would have to be done much like the printing. Set up an array, and then copy the stuff into it:

ThirdElementObj eoarray[]=new ThirdElementObj[100];
for(i=0; i<100; ++i)

NyTR0Author Commented:
Unfortunaltely the type of the field is not an object but int,
another question:  array[i].ThirdElementOfMyStruct can return many values of ThirdElementOfMyStruct  (example:  1332 and 955)  and I would see if I can find  the value 67343 for example in                           array[i].ThirdElementOfMyStruct
Is it possible?
System.out.println("Serial number"+ dda[i].snr);
// it prints 
Serial number 23432
Serial number 67343
Serial number 43556
// I would know if 67343 is contained in dda[i].snr

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.