How to copy an array element in one class to an array in another class?

Hi,
I have a ClassRoom class that stores a list of Student objects in an array. How would I copy a Student object from the Student[] array in the ClassRoom class to an array in another class?
Is it something like this:
System.arraycopy(Students, 2, AnotherClass.Array, 0, 2);In an array do the items get copied over existing array elements or can the be added to the end? If so, how would I specify add copied object reference to the end of the array in the other class?

drew22299 wrote:
Hi,
I have a ClassRoom class that stores a list of Student objects in an array. How would I copy a Student object from the Student[] array in the ClassRoom class to an array in another class?
Is it something like this:
System.arraycopy(Students, 2, AnotherClass.Array, 0, 2);In an array do the items get copied over existing array elements or can the be added to the end? If so, how would I specify add copied object reference to the end of the array in the other class?System.arrayCopy will overwrite whatever is already in the array. It is your job to make sure it copies into the proper array location.
That being said, you're only moving a single student. This is not something you would use arrayCopy for, as you can just do that with simple assignment. Also, you should consider giving Class a method to add a student to its student list, as the class should know how many students it has and can easily "append" to the array.
Note: I hope you noticed the quotes around append. Java's arrays are fixed size. Once allocated, their size cannot change. You may want to consider using one of the List implementations (ArrayList, for example) instead.

Similar Messages

  • How to copy and paste text from one photo book page to another.

    hello,i downloaded this software 2days ago,and i've been having so much fun with it. pls i need help on how to copy and paste text from one photo book page to another. Secondly how to copy my completed photo book pages project to another laptop for printing. thanks
    This question was solved.
    View Solution.

    Hi DG.
    The easiest way to copy an HP Photo Creations project to another computer is to click the Share button. That will upload the project to the Web and give you a link you can paste into an email. Clicking the link on the other computer allows you to download the project and personalize it. This quick video shows the process. (The screen looks slightly different now, but the concept is the same.)
    Another way to share a project is copy the project folder to a thumb drive. Look in Documents/HP Photo Creations/My Things to find your saved projects.
    Our customer support team would be happy to walk you through the process. Contact them at [email protected]
    Hope this helps,
    RocketLife 
    RocketLife, developer of HP Photo Creations
    » Visit the HP Photo Creations Facebook page — news, tips, and inspiration
    » See the HP Photo Creations video tours — cool tips in under 2 minutes
    » Contact Customer Support — get answers from the experts

  • How can I take an item from one image and move it to another image?

    How can I take an item from one image and add it to another image, and rotate it to fit?

    Carefully select the objects of interest in one image and then copy, scale and position them into the other image. Then touch up the composite.
    Have to Love Photoshop for Retouching Images!

  • I need sorting VI that returns the sorted array element's positions in the unsorted array

    I need a VI that will very quickly (n log n) sort a 1D array of doubles.  This VI should not only output the sorted array, but for each of the sorted array elements, it should also output that sorted array element's position in the unsorted array.  So for example if the input array were:
    unsorted_array
    4.1
    2.3
    7.0
    5.6
    10.2
    Then the output arrays would be:
    sorted_array
    2.3
    4.1
    5.6
    7.0
    10.2
    indices_array
    1 (the value 2.3 is located at position 1 in the unsorted_array)
    0 (the value 4.1 is located at position 0 in the unsorted_array)
    3 (the value 5.6 is located at position 3 in the unsorted_array)
    2 (the value 7.0 is located at position 2 in the unsorted_array)
    4 (the value 10.2 is located at position 4 in the unsorted_array)
    This way I could generate the sorted_array using just the indices_array and the unsorted_array.  Has anyone written a nifty piece of code to do this?  I did some research on (n log n) sorting algorithms but most of them use recursion which I don't know how to do in LabVIEW.  It would also be nice to have an algorithm like this that could sort an array of strings.
    cheers,
    Richard

    Try something like the attached example (LabVIEW 7.0). I think it does what you need.
    (To understand the code, it is important to know that arrays of clusters are sorted by the first element in the cluster).
    Sort array itself sorts also array of strings, so you could just substitute, keeping the rest of the code the same.
    Sort array uses a variation of quicksort, so it should have about NlogN complexity.
    (If you think you only need the array of indices to later generate the sorted array, it does not make much sense to even do it. To get the indices, you need to sort the array anyway. You should just sort the plain array directly.
    Message Edited by altenbach on 07-13-2005 03:47 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    SortAndIndex.vi ‏26 KB

  • How do i select a clip from one project and enter it into another?

    how do I select a clip from one project and enter it in another?

    This doesn't seem to relate to Adobe Reader. Please let us know the product you are using so we may redirect you or refer to the list of forums at http://forums.adobe.com/

  • How do I access array elements in one method from another method?

    Hi all!
    How do I access the array's elements from another method so that method 2 can have access to method 1's array elements? Thanks for any help!
    I am trying to create a simply program that will use a method to create an array and a SEPARATE method that will sort the array's elements (without using java's built in array features). I can create the program by simply having one method and sorting the array within that same method, BUT I want to sort the array from another method.
    Here's my code so far:
    public class ArraySort {
       public static void createArray(int size){
           double myArray[] = new double[size];    //create my new array
           for(int j=0; j < myArray.length; j++)
              myArray[j] = (200.0 * Math.random() + 1.0);   //fill the array with random numbers
       public static void sortArray(){
           // I WANT THIS METHOD TO ACCESS THE ARRAY ELEMENTS IN THE METHOD ABOVE, BUT DON'T KNOW
          //  HOW???? Please help!
        public static void main(String[] args) {
            createArray(4);    //call to create the array
    }Thanks again!
    - Johnny

    Thanks for the help all! I ve managed to get the program working, using java's built in array sort, but when i try to call on the array sort method from WITHIN my main method, nothing happens!
    Can somebody please tell me why I am not able to call on the sort method from within my main class???? Thanks!
    public class ArraySort {
       public void createArray(double[] arrayName, int size){
           double myArray[] = new double[size];  //create new array
           for(int j=0; j < myArray.length; j++)
              myArray[j] = (200.0 * Math.random() + 1.0);    //populate array with
           }                                                 //random Numbers
           sortArray(myArray); 
       } //Sort array(if I delete this & try to use it in Main method --> doesn't work???
       public void sortArray(double[] arrayName){
           DecimalFormat time = new DecimalFormat("0.00");
           Arrays.sort(arrayName);      //sort array using Java's built in array method
           for(int i = 0; i <arrayName.length; i++)
               System.out.println(time.format(arrayName)); //print arary elements
    public static void main(String[] args) {
    ArraySort newArray = new ArraySort(); //create a new instance
    double myArray[] = new double[0]; //create a new double array
    newArray.createArray(myArray,4); //build the array of indicated size
    //newArray.sortArray(myArray); //This will not work???? WHY?????//

  • How to copy all video sources to one central location?

    Hello
    Having picked up excellent tips from the forums and now overcome my initial hiccups I am now running Premiere Elements 8 very successfully and am, delighted with the results BUT I still have a nagging query.
    I am using a USB memory stick and an external HDD to bring video sources into my project to be editied and rendered. This works fine but of course whenever I want to amend the project, I need to plug in these devices again, no problem until one day in the future I don't have that particuilar stick or drive!!!!!
    Simple question is : How do I copy all these resources to one central location for current and future use please?
    I suppose this is a dumb question but please take in to account I'm a keen but very green newbie!!!  Many thanks in advance,
    Paul (UK)

    Steve, I just went through your Basic Training toturial and I have to say it was one of the clearest, well paced and immediately understandable series I've seen yet. You cover it all quickly and logically and I now see where I made soooooooooo many mistakes. Haven't Adobe head hunted you yet? One minor suggestion. . .  being a Brit, PAL is our standard and, because you have all nationalities viewing your material, it might be helpful for the PAL area to be mentioned in the initial project set up too. I know about PAL and NTSC but others may not. Hope you don't mind this tiny point? I can't thank you enough for the guidance you've given me already  . . . you're a very patient guy with us newbies! Thanks.
    Bill, thanks for the "thumbs up" too on those Harm set ups, it's good to get confirmation from someone who's done it and proved the case. I don't have RAID either but the settings below that level are perfectly fine for me. I'm really looking forward to my next, properly configured project.
    Thanks Bill

  • Hola!  How do I move an element of one picture to another?  PSE10, Windows 7.

    Please let me know how to move an element of one picture to another.  PSE10, Win. 7.

    Jona Lewa Koola wrote:
    Please let me know how to move an element of one picture to another.  PSE10, Win. 7.
    Select the "element" you want to "move" using any of the selection tools available in PSE and then either copy it using CTRL+C or Edit >> copy or cut it using CTRL+X or Edit >> Cut
    Now go to the other image and paste it using CTRL+V or Edit >> Paste
    if you cut it then it will "move" your "element" and remove from the original but if you copy and paste it then both images will have that copied item.
    After pasting it, you may need to move it to the correct location on the target image.
    Hope this helps.

  • How to copy the Pricing conditions from one Distribution Channel to another

    Generally we use VK11 transaction to create conditional records .
    but I Need to Know whether is it Possible to copy the Pricing conditions from one Distribution Channel to another with same name and same internal Characteristics .
    Since we have around 70+ of Condition type with different parameter Sequence.So Instead of Going for BDC whether is there any standard Funct Modules/programs/BAPIs to do this?
    How to make a copy Condition types from One Distribution Channel to another.
    since SAP has already provided to copy conditions from Customer to customer.
    Likewise i need to know whether SAP is facilitating for these feature also.
    Iam Dubious in this issue.
    Hope Fully looking for the answers.
    Harish.N

    - IDOC_INPUT_COND_A (you can create IDOC, but also call directly)
    - call transaction / batch input (use transaction XK15, as used by LSMW)
    - use group of function modules RV_CONDITION_COPY, RV_CONDITION_SAVE, RV_CONDITION_RESET + commit.
    if you search SDN on 'RV_CONDITION_COPY' you'll find more info I believe.
    Someone mentioned BAPI_PRICE_CONDITIONS as well.

  • How to set an array element in an object type of array??

    Hi,
    I have set attribute as follow:
    Color[] colors;
    Color[] colors = new Color[20];
    colors[0] = "Red";
    colors[1] = "blue";I can't compile this code. It said:
    "Incompatible type -found java.lang.String but expected Colors
    Could you tell me how to set an array elements when the array type is an object?

    in your case, the array shouldn't be Color[] but String[] since you re intending to put strings into it
    by the way, you could also use a hashmap to map a string to a color:
    HashMap<String, Color> hm = new HashMap<String, Color>();
    hm.put("Red", Color.RED);
    hm.put("Blue", Color.BLUE);
    etc.

  • How can copy GL account created at one chart of account to another COA

    Hello sap experts
    we have a requirement where client is using one chart of acocunt ND12 & they want to copy all the g.l account created at this chart of account to a new chart of account ND13.
    Kindly suggest is there any way to copy g.l accounts from one COA to another?
    Thanks & Regards
    Deepak Garg

    Use t-code OBY7 to copy COA.
    Use t-code OBY2 to copy Company Code Segment of GL A/c.
    Thanks

  • How can you take a photo from one event and put it in another, without dragging to desktop and dragging back into iPhoto and moving it to the event folder I want it in.

    As the title says I need help on how to take a photo from one event and put it in another, without dragging to desktop and dragging back into iPhoto and moving it to the event folder I want it in. Right now when I want to move a picture from one event to another I drag it to my desktop then delete it from iPhoto then I drag it back into iPhoto and put where I want it.An example would be taking a photo from the Christmas event and add it to a specific person event.  Can I do that within the events section without all the dragging. Also is there anyway I can remove duplicates from iPhoto without going through each and every file. Any help would be greatly appreciated.

    Apple doesn't make it easy to do what you want.  However, here's how I do it. 
    Select the photo you want to move and create a new Event for it via the Event ➙ Create Event menu option.
    In the Event mode select the new Event with the one picture and drag it onto the Event you want to move the photo to.

  • How do i deactivate now leopard from one computer and activate it into another?

    I updated with snow leopard my old computer and now i want to use it on another computer instead. how do i deactivate it from an old computer to use it with another one? since you cant use it on multiple computers i need to get this done! please help!

    Erase the drive or partition it was installed to, and then install it on the desired computer. There is no authentication or activation required for the client version of Mac OS X 10.6; Apple uses the honor system for it.
    (67521)

  • How to copy a text element to another in sapscript

    Question
    Have a bug in the system and need to copy an existing text element to a new one.
    How do you do this.
    I have found the text elelement in tihe MAIN window - the code /E   510-C  <-- this needs to be copied to a new text element called /E    510-A.  I can cust and paste this into the text element screen  But doesn't the 510-A refer to some text created via SO10?  But then doesn't sapscript require you to use an include to get the text in there?
    HELP - 2 days from go -live here!!
    Thanks and big points to who can ever help!

    Text elements are specified with "/E".  These are different from STANDARD TEXT objects that you define in SO10 and reference with the INCLUDE statment.
    Text elements are called from the ABAP print program.  If you copy text element 510-C to 510-A, the ABAP print program has to call element 510-A to execute the statements in this section.
    Are you dealing with errors from a syntax check?

  • How to copy the attribute values of one instance  into another instance.

    Say I have 3 instances and two attributes name ,id.
    inst1 : id:1 ,name:abc
    inst2: id:2 ,name:bcd
    inst3: id:3 ,name:efg
    now I want
    inst: id:1 ,name:abc
    bcd
    efg
    i.e is need to abort instance inst2 & inst3 before that copy the names bcd & efg to inst1.
    Please let me know how to do this its very urgent.

    Hi,
    The tricky part of this is to provide your third instance a way to find the other two instances. Finding instances in a process is a bit like finding rows in a database. When doing a SELECT statement in a database, you have a primary key that will guarantee you that you'll only retrieve one row. In Oracle BPM there are a couple ways to do this. One way is to use the instance's id (the predefined variable id.id) to search for the two instances. Another is to use a "correlation" to find the instances.
    This example assumes you'd like to look at instances based on a search filter. This filter assumes that you have a customerId variable that both of the instances share. It only returns those instances currently inside the process (the SearchScope logic below being set to "StatusScope.ONLY_INPROCESS" in the logic below). The only incoming variable it needs is the "customerId" variable that has already been set to some value in the other instance. Note that this uses the Fuego.Papi.ClientBusinessProcess object. This logic creates a search filter and only returns instances that meet a certain criteria (the two instances in the process). Once you get the instance, the "getVar()" method retrieves the "name" instance variable. This assumes that you have an instance variable "customerNames" defined as a String array that you are using to store the names retrieved from the two instances. The "abort()" method aborts the two instances it finds in the search.
    cbp as ClientBusinessProcess = ClientBusinessProcess()
    connectTo(cbp, processId : "/NameOfYourProcessHere")
    instF as InstanceFilter = InstanceFilter()
    create(instF, processService : cbp.processService, viewId : "TypeSearch")
    instF.searchScope = SearchScope(participantScope : ParticipantScope.ALL,
                                  statusScope : StatusScope.ONLY_INPROCESS)
    logMessage "Customer Id is: " + customerId  using severity = DEBUG
    addAttributeTo(instF, variable : "customerId",
                              comparator : IS, value : customerId)
    for each inst in getInstancesByFilter(cbp, filter : instF) do
       // get the value of the order's amount for the instance
        instanceVarValue as Object = getVar(inst, var : "name")
        customerNames[] = String(instanceVarValue)
        logMessage "Customer name is: " + String(instanceVarValue) 
                 using severity = DEBUG
        // aborts the instance in the process
        inst.abort()
    endHope this helps,
    Dan

Maybe you are looking for

  • I have parallels 7 and windows 7, how do I use Boot Camp and windows

    I have Parallels  version 7 installed on my MacPro5,1 mid 2010 (3.2ghz quad core) OSX 10.6.8 My question, can I run Windows from the Parallels 7 using Boot Camp app, or do I have to install it with Boot Camp on a  different partition ? I have never u

  • Getting Error while installing omwb

    Hi, I want to migrate sql server data to oracle database. When I am installing omwb in my computer getting error " No plug in install. Please install the plugin for the database you want to migrate. " 1. I don't know from where I have to download the

  • Integration repository architecture

    i want integration repository architecture

  • Password is wrong after a new start

    Hi everyone! I have a problem with my Macbook. I have made the last update and after restarting i was asked to type in my username and the password, like always. But since this last update and a restart it tells me the password is wrong. That ***** b

  • How to update List in Real time

    Hallo, i have a little problema with the List component (spark). I linked that list with my database e adding and removing data from that list with addItem and removeItem. This works fine with List because the List items appears and disappers in real