Link to home
Start Free TrialLog in
Avatar of NyTR0
NyTR0

asked on

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

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

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


   


Avatar of imladris
imladris
Flag of Canada image

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)
    eoarray[i]=array[i].ThirdElementOfMyStruct;

Avatar of NyTR0
NyTR0

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of imladris
imladris
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial