Copying Arrays

I have the following method to copy part of one array to another:
public static int[] subArray(int[] a, int left, int right){
     int j=0;
     int[] b=new int[100];
     for(int i=left; i >= right; i++){
     b[j]=a;
     j++;
     return b;
but when I test this it seems to give me the following output:
[I@310d42
Does anybody know why it does this? Thanks

public static void arraycopy(
Object source,
int srcIndex,
Object dest,
int destIndex,
int length,
public int[] copypartofarray(int[] a, int left, int right){
int n = (left - right)+1;
if(n < 0){n = -n;}
int[] b = new int[ n ]
System.arraycopy(a,left,b,0,n);
return b; // i think that's about right 
//or to make the new array any size your going to need to add saftey
//check's to make sure you dont get a index out of bound's exception
public int[] copypartofarray(int[] a, int left, int right,int newarraylenghth){
int[] b = new int[ newarraylenghth ]
System.arraycopy(a,left,b,0,newarraylenghth);
return b;
}hope that's what your looking for.

Similar Messages

  • Copying arrays, performance questions

    Hello there
    The JDK offers several ways to copy arrays so I ran some experiments to try and find out which would be the fastest.
    I was measuring the time it takes to copy large arrays of integers. I wrote a program that allocates arrays of various sizes, and copy them several times using different methods. Then I measured the time each method took using the NetBeans profiler and calculated the frequencies.
    Here are the results I obtained (click for full size):  http://i.share.pho.to/dc40172a_l.png
    (what I call in-place copy is just iterating through the array with a for loop and copying the values one by one)
    I generated a graph from those values:  http://i.share.pho.to/049e0f73_l.png
    A zoom on the interesting part: http://i.share.pho.to/a9e9a6a4_l.png
    According to these results, clone() becomes faster at some point (not sure why). I've re-ran these experiments a few times and it seems to always happen somewhere between 725 and 750.
    Now here are my questions:
    - Is what I did a valid and reliable way to test performances, or are my results completely irrelevant? And if it's not, what would be a smarter way to do this?
    - Will clone be faster than arraycopy past 750 items on any PC or will these results be influences by other factors?
    - Is there a way to write a method that would copy the array with optimal performances using clone and arraycopy, such that the cost of using it would be insignificant compared to systematically using one method over the other?
    - Any idea why clone() can become faster for bigger arrays? I know arraycopy is a native method, I didn't try to look into what it does exactly but I can't imagine it's doing anything more complicating than copying elements from one location in the memory to another... How can another method be faster than that?
    (just reminding I'm copying primitives, not objects)
    Thanks!
    Message was edited by: xStardust! Added links, mr forum decided to take away my images

    yeh, everyone thinks that at some point. it relies,
    however, on you being perfect and knowing everything
    in advance, which you aren't, and don't (no offence,
    the same applies to all of us!). time and time again,
    people do this up-front and discover that what they
    thought would be a bottleneck, isn't. plus,
    the JVM is much smarter at optimizing code than you
    think: trust it. the best way to get good performance
    out of your code is to write simple, straightforward
    good OO code. JVMs are at a point now where they can
    optimize java to outperform equivalent C/C++ code
    (no, really) but since they're written by human
    beings, who have real deadlines and targets, the
    optimizations that make it into a release are the
    most common ones. just write your application, and
    then see how it performs. trust me on this
    have a read of
    [url=http://java.sun.com/developer/technicalArticles/I
    nterviews/goetz_qa.html]this for more info anda chance to see where I plagiarized that post from :-)
    Thanks for that link you gave me :)
    Was usefull to read.
    About time and money of programming, that is not really an issue for me atm since i'm doing this project for a company, but through school (it's like working but not for money).
    Of course it should not last entirely long but I got time to figure out alot of things.
    For my next project I will try to focus some more on building first, optimizing performance later (if it can be done with a good margin, since it seems the biggest bottlenecks are not the code but things outside the code).
    @promethuuzz
    The idea was to put collection objects (an object that handles the orm objects initialized) in the request and pass them along to the jsp (this is all done through a customized mvc model).
    So I wanted to see if this method was performance heavy so I won't end up writing the entire app and finding out halve of it is very performance heavy :)

  • Copy array and sort the numbers in the new array

    Hi!
    I have an array containing some digits where some of the digits are zeros. I want to copy the digits to another array but the zeros (well, I actually want to copy the zeros as well but I want to have them in the end of the new array).
    I suppose I need an if-statement that checks if the old array contains any zeros and in that if-statement copy the content to the new array and put the zeros in the end.
    This is my code so far and I don�t know how to go on from here:
    int[] new_array = new int[array.length];
              for (int i = 0; i < array.length; i++)
                   if (array[i] > 0)
                        new_array[i] = array;
                        new_array = array;
                   System.out.print(new_array[i] + " ");

    Roxxor wrote:
    I think I know how to do it but only if I can catch the digits bigger than zero.
    My code below just checks if there are positive digits and if there are, the whole old array is copied to the new one.Yes. Don't do that, you can see it's wrong.
    So my problem is that I don�t know how to catch the digits bigger than zero and copy them. Is there any built in java keyword that catches signs, number etc?
    if (array>=0)
         new_array[i] = array[i];
         new_array = array;
    Yes, there is such a keyword. And you are already using it correctly in your code. You are already testing if the array entry is bigger than zero. Your only problem is, you don't know what to do when it is. But now you've been given two hints about what to do.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Copying Arrays - Instance Variables - Multiple Animations

    Hi All!
    Thanks so much, in advance, as always, for your assistance!
    So, here's a site I'm working on:
    http://www.mediamackenzie.com/cmix/cmix10.html
    I have 3 quick questions:
    - I tried, when I first started making this site, to load all of the artwork images into an array and then copy the array before resizing them for their specific functions (being seen as thumbnails or as full size pics.) Unfortunately, I ran into the well known issue of Array cloning only creating a pointer to the same group of items. I tried the newArray = oldArray.slice() trick, but it didn't seem to work. Finally, I just loaded the images twice into two separate arrays, and it works, but I hate this solution. Anyone got a better one?
    - I'm trying to maintain some sort of connection between the two sets of Arrays so that, for example, when someone clicks on Thumbnail 15, Fullsize Image 15 will open up but I couldn't find anything that worked. Renaming the Instance Name dynamically didn't seem to work and adding an Instance Variable dynamically doesn't seem possible either as I can't make the Class I am working with (Sprite, in this case) dynamic ahead of time. I'm sure there's a simple method for this. Any suggestions?
    - Lastly, notice how when the site opens up, the different animations seem to interfere with each other and slow each other down (they also seem to get interference from the time taken to load the image Arrays.) Anyone got any high level suggestions for how to avoid this?
    Thanks So Much!
    and Be Well
    Graham

    I'm still stuck, but close, I think. The URL: http://www.mediamackenzie.com/cmix/cmix11.html
    Here is the code from frame 1 of my Gallery MovieClip (an instance of which is created dynamically in the main timeline):
    stop();
    import fl.transitions.Tween;
    import fl.transitions.easing.*;
    var idealH = 120;
    var idealW = idealH + 50;
    var loadH = 300;
    var loadW = loadH * 2;
    var thumb = 0;
    var loadNum = 0;
    var thumby:Sprite;
    var darkStage:Sprite;
    var loadSprite:Sprite;
    var thumbArray:Array = new Array();
    var loadArray:Array = new Array();
    var bigLoad:Loader;
    var reSized:Boolean = false;
    this[thumb] = new Loader();
    this[thumb].contentLoaderInfo.addEventListener(Event.COMPLETE, thumbComplete);
    this[thumb].load(new URLRequest("images/0.png"));
    thumbArray.push(this[thumb]);
    function thumbComplete(e:Event):void {
        trace("thumbComplete");
        thumb++;
        this[thumb] = new Loader();
        this[thumb].load(new URLRequest("images/" + thumb + ".png"));
        thumbArray.push(this[thumb]);
        this[thumb].contentLoaderInfo.addEventListener(Event.COMPLETE, thumbComplete);
        this[thumb].contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, thumbError);
    function thumbError(e:IOErrorEvent):void {
        trace("thumbError");
        thumb = 0;
        thumbArray.pop();
        loadArray = thumbArray.slice();
        gotoAndStop(2);
    Now, here is the code from frame 2:
    //stop();
    addArrows();
    thumbResize();
    loadResize();
    function thumbResize():void {
    trace("thumbResize");
        for (var batch = 0; batch < Math.ceil(thumbArray.length / 8); batch++) {
            trace("batch " + batch);
            var batchSprite: Sprite = new Sprite();
            batchSprite.x = (batchSprite.x + (idealW / 1.5) + (batch * 800));
            //batchSprite.mouseEnabled = false;
            addChild(batchSprite);
            for (var row = 0; row < 2; row++) {
                trace("     row " + row);
                for (var col = 0; col < 4; col++) {
                    trace("          col " + col);
                    trace("               thumb " + thumb);
                    //If the width of the image is greater than the ideal width, OR the height is greater than the ideal height...
                    if ( thumbArray[thumb].content.width > idealW || thumbArray[thumb].content.height > idealH) {
                        //And if the width of the image is greater than the height, apply Scaler 1...
                        if ( thumbArray[thumb].content.width > thumbArray[thumb].content.height ) {
                            //Scaler 1 is the ratio of the ideal width to the image width
                            var scaler1 = idealW / thumbArray[thumb].content.width;
                            trace("               scaler1 = " + scaler1);
                            //Apply Scaler 1 to both the width and height of the image
                            thumbArray[thumb].content.scaleX = thumbArray[thumb].content.scaleY = scaler1;
                            trace("               image width:" + thumbArray[thumb].content.width);
                            trace("               image height:" + thumbArray[thumb].content.height);
                            //Otherwise, apply Scaler 2
                        } else {
                            //Scaler 2 is the ratio of the ideal width to the image height
                            var scaler2 = idealW / thumbArray[thumb].content.height;
                            trace("               scaler2 = " + scaler2);
                            //Apply Scaler 2 to both the width and height of the image
                            thumbArray[thumb].content.scaleX = thumbArray[thumb].content.scaleY = scaler2;
                            trace("               image width:" + thumbArray[thumb].content.width);
                            trace("               image height:" + thumbArray[thumb].content.height);
                        //Otherwise... (that is, the image width and height are in both cases less than the ideal)
                    } else {
                        //And if the width of the image is greater than the heigh, apply Scaler 3
                        if ( thumbArray[thumb].content.width > thumbArray[thumb].content.height ) {
                            //Scaler 3 is the ratio of the ideal width to the image width
                            var scaler3 = idealW / thumbArray[thumb].content.width;
                            trace("               scaler3 = " + scaler3);
                            //Apply Scaler 3 to both the width and height of the image
                            thumbArray[thumb].content.scaleX = thumbArray[thumb].content.scaleY = scaler3;
                            trace("               image width:" + thumbArray[thumb].content.width);
                            trace("               image height:" + thumbArray[thumb].content.height);
                        } else {
                            //Scaler 4 is the ratio of the ideal width to the image height
                            var scaler4 = idealW / thumbArray[thumb].content.height;
                            trace("               scaler4 = " + scaler4);
                            //Apply Scaler 4 to both the width and height of the image
                            thumbArray[thumb].content.scaleX = thumbArray[thumb].content.scaleY = scaler4;
                            trace("               image width:" + thumbArray[thumb].content.width);
                            trace("               image height:" + thumbArray[thumb].content.height);
                    thumbArray[thumb].content.x = - (thumbArray[thumb].content.width / 2);
                    thumbArray[thumb].content.y = - (thumbArray[thumb].content.height / 2);
                    thumby = new Sprite();
                    thumby.addChild(thumbArray[thumb]);
                    thumby.y = (row * (idealW + (idealW / 8)));
                    thumby.x = (col * (idealW + (idealW / 8)));
                    thumby.buttonMode = true;
                    thumby.useHandCursor = true;
                    thumby.addEventListener(MouseEvent.CLICK, enLarge);
                    batchSprite.addChild(thumby);
                    thumb++;
    function loadResize():void {
        trace("loadResize");
        for (var ex = 0; ex < loadArray.length; ex++) {
            //If the width of the image is greater than the ideal width, OR the height is greater than the ideal height...
            if ( loadArray[loadNum].content.width > loadW || loadArray[loadNum].content.height > loadH) {
                //And if the width of the image is greater than the height, apply Scaler 1...
                if ( loadArray[loadNum].content.width > loadArray[loadNum].content.height ) {
                    //Scaler 1 is the ratio of the ideal width to the image width
                    var scaler1 = loadW / loadArray[loadNum].content.width;
                    //Apply Scaler 1 to both the width and height of the image
                    loadArray[loadNum].content.scaleX = loadArray[loadNum].content.scaleY = scaler1;
                    //Otherwise, apply Scaler 2
                } else {
                    //Scaler 2 is the ratio of the ideal width to the image height
                    var scaler2 = loadW / loadArray[loadNum].content.height;
                    //Apply Scaler 2 to both the width and height of the image
                    loadArray[loadNum].content.scaleX = loadArray[loadNum].content.scaleY = scaler2;
                //Otherwise... (that is, the image width and height are in both cases less than the ideal)
            } else {
                //And if the width of the image is greater than the heigh, apply Scaler 3
                if ( loadArray[loadNum].content.width > loadArray[loadNum].content.height ) {
                    //Scaler 3 is the ratio of the ideal width to the image width
                    var scaler3 = loadW / loadArray[loadNum].content.width;
                    //Apply Scaler 3 to both the width and height of the image
                    loadArray[loadNum].content.scaleX = loadArray[loadNum].content.scaleY = scaler3;
                } else {
                    //Scaler 4 is the ratio of the ideal width to the image height
                    var scaler4 = loadW / loadArray[loadNum].content.height;
                    //Apply Scaler 4 to both the width and height of the image
                    loadArray[loadNum].content.scaleX = loadArray[loadNum].content.scaleY = scaler4;
            loadArray[loadNum].content.x = - (loadArray[loadNum].content.width / 2);
            loadArray[loadNum].content.y = - (loadArray[loadNum].content.height / 2);
            loadNum++;
    function addArrows():void {
        trace("addArrows");
        var batches =  Math.ceil(thumbArray.length / 8);
        var m = 0;
        trace("batches = " + batches);
        if (batches > 1) {
            for (var k = 1; k < batches; k++) {
                var triW = 20;
                var startX = (((800 - triW) * k) + (triW * m));
                var startY = (idealW / 2);
                var tri:Sprite = new Sprite();
                tri.graphics.beginFill(0xFFFFFF);
                tri.graphics.moveTo(startX, startY);
                tri.graphics.lineTo(startX, (startY + triW));
                tri.graphics.lineTo((startX + triW), (startY + (triW/2)));
                tri.graphics.lineTo(startX, startY);
                tri.graphics.endFill();
                tri.buttonMode = true;
                tri.useHandCursor = true;
                tri.addEventListener(MouseEvent.CLICK, moveLeft);
                addChild(tri);
                var tri2:Sprite = new Sprite();
                var startX2 = (startX + (triW * 2));
                tri2.graphics.beginFill(0xFFFFFF);
                tri2.graphics.moveTo(startX2, startY);
                tri2.graphics.lineTo(startX2, (startY + triW));
                tri2.graphics.lineTo((startX2 - triW), (startY + (triW / 2)));
                tri2.graphics.lineTo(startX2, startY);
                tri2.graphics.endFill();
                tri2.buttonMode = true;
                tri2.useHandCursor = true;
                tri2.addEventListener(MouseEvent.CLICK, moveRight);
                addChild(tri2);
                m++;
    function moveLeft(event:MouseEvent):void {
        var leftTween:Tween = new Tween(this, "x", Regular.easeOut, this.x, (this.x - 800), .5, true);
    function moveRight(event:MouseEvent):void {
        var rightTween:Tween = new Tween(this, "x", Regular.easeOut, this.x, (this.x + 800), .5, true);
    function enLarge(event:MouseEvent):void {
        darkStage = new Sprite();
        darkStage.graphics.beginFill(0x000000, .75);
        darkStage.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
        darkStage.addEventListener(MouseEvent.CLICK, reMove);
        darkStage.buttonMode = true;
        darkStage.useHandCursor = true;
        parent.addChild(darkStage);
        var nmbr = thumbArray.indexOf(event.currentTarget);
        bigLoad = new Loader();
        bigLoad = loadArray[nmbr];
        trace("bigLoad: " + bigLoad);
        loadSprite = new Sprite();
        loadSprite.addChild(bigLoad);
        loadSprite.x = (stage.stageWidth / 2);
        loadSprite.y = (stage.stageHeight / 2);
        loadSprite.addEventListener(MouseEvent.CLICK, reMove);
        loadSprite.buttonMode = true;
        loadSprite.useHandCursor = true;
        parent.addChild(loadSprite);
    function reMove(event:MouseEvent):void {
        parent.removeChild(darkStage);
        parent.removeChild(loadSprite);
    The function enLarge is the source of the issue (I want the enlarged image to show up and it's not.)
    Please help if you can!
    Thanks,
    Graham

  • Problem shifting (copying) array elements in a list

    I am trying to add points to the beginning of a list. However, I cannot seem to debug the insertBeginning( ) method. I am faced with a problem that overwrites certain array elements. If I can get any help I would greatly appreciate it.
    Thanks,
    I have included a sample run and some code.
    The following url contains both the main and the class files.
    http://lbbmx.com/java/
    public void appendZ ( Point newPoint ) // used w/ insertBeg method
         size++;
         cursor=0;
         ptlist[cursor]= newPoint;
    public void insertBeginning ( Point newPoint )      // Insert begin.
              if(this.isEmpty())
                {append(newPoint);}
             else
              cursor=0;
              for(int i=size; i>cursor; i--)
                  ptlist[size]= ptlist[size-1];   //pt[1]=pt[0]
              this.appendZ(newPoint);Here is a sample run:
    Commands:
      + x y  : Append point (x,y) to the end of the list
       # x y  : Insert point (x,y) at beginning
       Q      : Quit the test program
    Empty list
    Command: +1 1
    Append (1,1)
    size = 1   cursor = 0
    0     1     2     3     4     5     6     7     
    (1,1)     
    Command: #2 2
    Insert (2,2) at beginning
    size = 2   cursor = 0
    0     1     2     3     4     5     6     7     
    (2,2)     (1,1)     
    Command: #3 3
    Insert (3,3) at beginning
    size = 3   cursor = 0
    0     1     2     3     4     5     6     7     
    (3,3)     (1,1)     (1,1)     

    ptlist[size]= ptlist[size-1];In this situation, size is the variable you are keeping track of how many elements are in your array. This does not change until after you have inserted the new Point. So, regardless of how many times you go around the loop you are simply copy the same value.
    "How do I fix it?" I hear you ask.
    Well what changes everytime you go around the loop?

  • Copy Array and change LowerCase to UpperCase

    In the following code Array numAlph contains character 97, 98, and so forth and when printed is a, b, c. I am to copy this Array into another Array and make the LowerCase into UpperCase. Can anyone show me how this can be done? Thanks in advance. I will award 10 Duke pts. on completion.
    public class AlphaUpper
    *Reads in 26 Chars Alphabet in lowercase
    public void main(String[] args)
    AlphaUpper newalph = new AlphaUpper();
    int x;
    char unialph = 97;
    char[] numAlph = new char[26];
    for (x = 0; x < numAlph.length; ++x)
    numAlph[x] = unialph ++; // Loads 97 98 99 ....
    x = 0;
    for (x = 0; x < numAlph.length; ++x )
    System.out.print(" " + numAlph[x]); // Print Array

    What about this one:
    public class AlphaUpper{
      public static void main(String[] args){
        AlphaUpper newalph = new AlphaUpper();
        int x;
        char unialph = 97;
        char[] numAlph = new char[26];
        for (x = 0; x < numAlph.length; ++x)
          numAlph[x] = unialph ++; // Loads 97 98 99 ....
        String alphabet = "";
        for (x = 0; x < numAlph.length; ++x){ // copy it into a String
          alphabet = alphabet+numAlph[x];
        alphabet = alphabet.toUpperCase(); // change lower to upper
        for (x = 0; x < numAlph.length; ++x){ // copy String back to array
          numAlph[x] = alphabet.charAt(x);
        for (x = 0; x < numAlph.length; ++x){
          System.out.print(" " + numAlph[x]); // Print Array
    }I'm sure this isn't the way your teacher want you to solve the problem, but: why not? :-)

  • The System.arraycopy Functionality and copying array question

    When created arrays such as String[] myStringArray (for example), is it general good practice to use the System.arraycopy function to copy the array?
    Why isn't it good practice to use equal instead? Would this work just as well?
    String[] myStringArray = new String[] { "My", " Test"};
    String[] myStringArrayCopy = new String[myStringArray.length};
    myStringArrayCopy = myStringArrayCopy;Or is that just going to make them the same element in memory and if I change myStringArray in antoher part of the program that means myStringArrayCopy will change as well since it is the same thing?

    Youre right, the equals sign just assigns the new array same reference in memory as the old array so they are pointing to the same data.
    Im 90% sure of that.
    If you want to work with an array without changing the original array id suggest using the System.arraycopy method. If you dont mind the contents changing then use the = sign..(but then why use a new array at all?)
    Hope this helps, if not theres loads of more experienced people on the boards...
    Ocelot

  • Howto efficiently Copy array into data portal

    I have an array in VBS memory and would like to create an channel in the data-portal based on that data-set, I currently use this code construct to copy the data:
    ' intChannelCount is the number of samples
    'MaxHold is the data array to be copied
    'oFFTMaxHold is the data channel that is the target of the data
    for counter = 1 to intChannelCount
          oFFTMaxHold.Values(counter)=MaxHold(counter)
    next
     It is rather slow (and if the data preview is open in the data portal) even much slower.
    Is there a method to copy the whole array in one operation to a channel?
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!
    Solved!
    Go to Solution.

    Hi Ton,
    If you have DIAdem 10.2 or later you can use the following command to do this with one command-- passing the array of values as one of the command's parameters-- this is a common situation when querying records from a data base that you want to load into the Data Portal as channels.
    ChanRefsArray = ArrayToChannels(ValuesArray, ChanNamesArray)
    In the case of your example below, that would be:
    Call ArrayToChannels(MaxHold, Array(oFFTMaxHold.Name))
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments

  • Urgent query about copying array of objects to html item

    I have an urgent query about how I can display an array of objects on a html form. The only suitable html item I can see for this is a drop down box. Ideally a combo box would be preferable but I cant find anything like this. Basically the display item needs to contain 3 columns of data and has to display a number of rows. Can anyone tell me how to copy the array of values into a drop down box?

    Here is all the code from my jsp. It keeps returning null:
    <%@ page language="java" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ page import="java.util.*, java.lang.*" %>
    <html:html locale="true">
    <head>
    <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252"/>
    <link rel="stylesheet" type="text/css" name="timesheet" href="stylesheets/timesheet.css"></link>
    <script type="text/javascript" language="javascript" src="javascript/sum.js"></script>
    <title><bean:message key="eng.title"/></title>
    <html:base/>
    </head>
    <body bgcolor="white">
    <table border="0" width="100%">
    <tr>
    <td width="30%"><html:img page="/images/PwC_logo.gif"/></td>
    <td width="40%" class="applicationTitleCell">
    <div align="center">
    <bean:message key="application.title"/>
    </div>
    </td>
    <td width="30%"> </td>
    </tr>
    </table>
    <center>
    <html:form action="/selectEng" focus="engSearchNumber">
    <table border="0" width="100%">
    <tr>
    <td width="30%"></td>
    <td width="20%" align="center"> <b> <bean:message key="eng.prompt.engSearchNumber"/> </b> </td>
    <td width="20%" align="center"> <b> <bean:message key="eng.prompt.clientSearchName"/> </b> </td>
    <td width="40%">   </td>
    </tr>
    <tr>
    <td width="30%"></td>
    <td width="20%" align="center"> <html:text property="engSearchNumber" size="20" maxlength="9" onchange='<%= "SearchLength(this)" %>' onkeypress="return NumberOnly()" /> </td>
    <td width="20%" align="center"> <html:text property="clientSearchName" size="20" maxlength="20" onchange='<%= "SearchLength(this)" %>'/> </td>
    <td width="30%">   </td>
    </tr>
    </table>
    <table border="0" width="100%">
    <tr>
    <td width="30%"></td>
    <td width="40%" align="center"><html:image property="findButton" src="images/Find.gif" alt="Find"/></td>
    <td width="30%">   </td>
    </tr>
    <jsp:useBean id="selectEngForm" scope="session" class="Time.SelectEngForm" />
    <% if (selectEngForm.getEngSearchNumber() != null) { %>
    <tr>
    <td width="30%"></td>
    <td width="40%" align="center"><select name="engListing" size="5">
    <%= selectEngForm.getEngListing() %>
    </select></td>
    <td width="30%">   </td>
    </tr>
    <% } else if (selectEngForm.getClientSearchName()!=null){ %>
    <tr>
    <td width="30%"></td>
    <td width="40%" align="center"><select name="engListing" size="5">
    <%= selectEngForm.getEngListing()%>
    </select></td>
    <td width="30%">   </td>
    </tr>
    <% } %>
    <%=request.getParameter("engListing")%>
    </table>
    <br><br>
    <table border="0" width="100%">
    <tr>
    <td width="30%"></td>
    <td width="11%" align="center"> <html:image property="addButton" src="images/Add.gif" alt="Add the selected engagement to the timesheet"/> </td>
    <td width="11%" align="center"> <html:image property="cancelButton" src="images/Cancel.gif" alt="Cancel"/> </td>
    <td width="30%">   </td>
    </tr>
    </table>
    </html:form>
    </center>
    <br>
    <center><html:link forward="timesheet"> <html:img src="images/Back.gif" border="0"/> </html:link></center>
    </body>
    </html:html>

  • Copy Array Quick Question

    Just a quick question.
    Say I have an array A = [1,2,3,4,5]
    B = new int[5]
    I understand to copy the elements of A into B we could use a for loop.
    But can somebody explain to me why you can't just go B = A?
    Does this just cause B to point to A?
    So how do arrays work exactly? Is it like in C where each element is actually a pointer to the data, or does Java copy the data directly into the array element?

    Kayaman wrote:
    JT26 wrote:
    Array A=[1,2,3,4,5] ----> Here A is a reference variable which points to memory locations A[0],A[1],A[2],A[3],A[4] which could not be continueous.Actually no. What you have there is a syntax error. And please don't confuse people by talking about non continuous memory locations. That's simply wrong.And 100% irrelevant for the question at hand.
    >
    B = new int[5] -----> Here B is another reference variable points to an array which could hold 5 elemets.That is correct, basically.
    All the five element holders of B could be physically any where in the memory, thus copying the the elements is done via a for loop.No, Java is smart enough to store arrays sequentially in memory. And the smart way to copy large arrays is System.arrayCopy().Or java.util.Arrays.copyOf.

  • Copy and paste array between instances?

    I have A.vi and B.vi. The last time I used these was in 8.6. I now have to use them on a machine with 8.2, but A.vi does not work in 8.2 without a bunch of tweaking, so I made it A.exe.
    A.exe builds and recalls files that contain arrays of DaqMx channels. I create long lists of channels once, and then since they are stored to a file, do not have to create them again. In the past, instead of adding code to B.vi to call the file, I would just open the file I wanted with A.vi, then copy the data from the array of channels, and paste it into the front panel of B.vi before pressing run.
    I cannot do this now. Is it because A is an EXE so the two are in different Application instances? I have not tried making B an EXE (nor do I want to), but I think it wouldn't matter because they would still be in different instances?

    You recreated numeric and string controls in an EXE. I agree that you can swipe these, CTRL C, and then CTRL V in to a VI. If I replace the CTRL C action with a Right Click> copy data, I get a picture in the VI.
    I can go to a numeric or text control or indicator within my EXE, right click, copy data, then paste that into another control within my EXE. If I then immediately go to a control in the VI, the Right Click>paste data option is greyed out and doing CTRL V drops a picture of the controlon the front panel. I did not select the control when I copied, I only highlighted the data inside the control.
    CTRL C or CTRL V is never an option when operating on array controls. I do not want to copy and paste individual lines of the array, I want the whole array data. This is done by right clicking on the numeric within the array index display and choosing copy data. In an EXE, this is your first option. In a VI while running, this is the third option. In a VI while not running, this is under data operations.
    I tried every combination of running and not running, and took screenshots, but it is hard to see exaclty what action I am performing.
    Attachments:
    Copy Array Data Running.jpg ‏37 KB
    Can't Paste Running.jpg ‏22 KB
    CTRL V of Right Click Copied Text.jpg ‏24 KB

  • Deep and Shallow array copy  again

    I am a Computer Analyst and a Java tutor.
    I am trying to understand the terms Shallow and Deep copy
    for arrays, using an example.
    Can you please tell me if my shallow and deep copy below is correct?
    Does the shallow copy not need any memory allocation?
    public Security( int paramAccountNumbers[], String paramPasswords[] ){
    String passwords[];
    int accountNumbers[];
    // INT ARRAY SHALLOW COPY
    accountNumbers = paramAccountNumbers;
    // STRING ARRAY DEEP COPY
    passwords = new String[paramPasswords.length];
    for( int i=0; i<paramPasswords.length; i++ ){
    passwords[i] = paramPasswords;

    You should use clone to copy arrays that contain only references to immutable objects or primitives.
    // "shallow" copy
    final String[] orig = new String[] {"a", "b", "c"};       
    final String[] copy = orig.clone();
    // or java 6 "shallow" copy
    final String[] orig = new String[] {"a", "b", "c"}; 
    final String[] copy = Arrays.copyOf(orig, orig.length, String[].class);If the array contains references to mutable objects you need to clone each element in the array
    // "deep" copy
    final Date[] orig = new Date[] {new Date()};
    final Date[] copy = new Date[orig.length];       
    for (int i = 0; i < orig.length; i++) copy[i] = (Date) orig.clone();However even this may not be sufficient in some cases, which is why cloning is a bit of a minefield.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Array Copy Problem

    ARRAY COPY DOESN'T WORK. DO NOT ATTEMPT TO USE IT IN YOUR REPLY TO THIS TOPIC. array copy says that you need the same type of object in the arrays. I'm making a method in a class called SUPERARRAYUTIL where this isn't the case. They all extend from a class i made called SUPERARRAY (in javacase caps tho, i just like to use upper case), but that doesnt help me. I'm short on time and i want to post this right now, so i won have any code right away but here is how i'm gonna do it:
    1) Static method takes parameters superArray array, superArray newelements, and int start
    2) Make a temp array that would be big enough to fit array, and the newelements at postion start in array
    3) copy over array using a for loop, starting at 0 in temp.
    4) copy over newelements using a for loop, starting at start in temp.
    Then i will make non-static methods for superArrayUtil that will use the static methods in superArrayUtil. I will also make a method like System.arraycopy but will call a method called cut to trim the array of new elements and then call this arraycopy to copy it into the dest array, and then another non-static method for that method too.
    Basically i just need ideas or comments cause so far i ran into some weird problems or any suggestions if there's a better way to copy arrays in the general way of array1 into array2 at a starting position.

    Deo_Favente wrote:
    ARRAY COPY DOESN'T WORK.
    YES. YES IT DOES. WHY DO YOU THINK THAT IT DOESNT WORK? WHY DON'T YOU POST WHATEVER CODE THAT YOU DO HAVE THAT IS CAUSING YOU PROBLEMS AND THEN MAYBE WE COULD WORK WITH IT. I THINK THAT'S A BETTER IDEA PERSONALLY, AT LEAST OPPOSED TO WHAT YOU DID HERE._+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • XSERVE RAID - copying to array causes "error -50"

    I am a n00b when it comes to administering an XSERVE RAID, so this may be something you can easily answer...
    I have a brand new XServe with XSERVE RAID attached using a fibre channel card. The upper controller is connected to the left-side of the array, array 1, while the right-side of the controller is connected to the lower controller, array 2. Each array is 4.08 TB, the entire array is stocked with 750GB HDDs.
    Array 1 has no problems copying, deleting, etc. Array 2 times out after I try to copy files, either across the network or using an external FW800 drive (2TB) from LaCie. I am trying to dump a lot of video data, and it blows up giving me an error -50. After that, I can't delete or do anything. Initially I thought this was due to ownership/file permissions but that doesn't make a difference. The external drive copies to Array 1 with no issues either. Any advice?

    Any updates on this? I think I am experiencing something similar.
    We have a Xserve RAID that has 1 array for our file server and we have just added 5 750GB drives to the right side of the RAID for a 2nd array. I spent most of the Thanksgiving break dealing with crashes and corrupt drives in Array 2 trying to migrate the files from the original array to the new array.
    Array 1 works just fine, but if I try to copy large files to the 2nd array things go haywire and the server usually "crashes". If I use Carbon Copy Cloner to copy Array 1 to our Wiebetech RAID box things are fine, however if I use the same process to copy Array 1 to Array 2 and even the Wiebetch box to Array 2, then the server "crashes". I say crashes since I don't really know what is going on. When I come back to check on things the server has locked up and isn't responding to anything or has restarted and I am back at the login screen. Array 2 will have been "corrupted" and won't mount unless I reformat via disk utility.
    In the RAID Admin events the only thing I get is that both controller 1 and 2 have gone down and are back up. The system log on the sever looks fine.
    Just trying to see if it was a cable or some other hardware issue.
    Thanks
    Carl

  • Copying value of objects, not reference?

    This has been bothering me for a while. I learned that when you set one object equal to another you are really just assigning the same reference to both, so that if one is altered they are both altered. Well, how can you set one object equal to the value of another but not the same reference so that altering one will not alter the other. My concern stems from returning arrays in methods. Since the reference itself is passed, any changes I make to the array are permanent, correct, and not just existing inside the method? So I was thinking maybe the best solution would be to use a tmp{] variable that is equal to the VALUE of the array I pass in, and then return that, so the original array is not altered in any way. Is this the customary practice for dealing with such situations? If not, what is typically done? Oh and just for future reference, because it might be of value to know, how DO I copy a value and not a reference? (and yes, that WAS on purpose ;) )

    violagirl23 wrote:
    My concern stems from passing arrays to [KRC] methods. Since the reference itself is passed, any changes I make to the array are permanent, correct, and not just existing inside the method? So I was thinking maybe the best solution would be to use a tmp{] variable that is equal to the VALUE of the array.Both georgemc and tschodt have already given you some good pointers, I'll try not to reiterate the same advise.
    This is an old "problem", discussed at length by folks much smarter than myself, and (IMHO) there still is no definitive question, let alone universal answer. What I mean is that sometimes this ability to modify the contents of a collection or array within a method is highly desirable; and sometimes of course it's just a source of bugs, when a noob calls your method not realising that it modifies the contents of the passed array (which shouldn't make it past unit testing anyway)... So, I think probably the best thing I can do for you is to give you the terms to google.
    What you're talking about is called a defensive copy... which, especially with arrays and collections, typically involves a deep copy (make a copy of every attribute of every object, all the way down the reference tree)... as apposed to Arrays.copyOf, which is a shallow copy, i.e. it just copies the references to the "top" objects.
    If you're writing a system from scratch you could decide to implement clone methods for everything you ever need to defensive copy. Cloning is ugly, no matter how you cook it. It requires every part of the class heirarchy being cloned to support the clone method (properly).
    In the past, I've tried to write a "generic" copy method, in the abstract-base-type of a class heirarchy using reflections. Everything I've tried has "pretty fatal" flaws. The only "proper" solution (AFAIK) is to just implement clone in every single frickin class... and that's a lot more "boiler plate" code than I personally think should be required to implement such a common, mundane task.
    Alternately, you could make all your data transfer objects immutable, so a shallow copy (Arrays.copyOf) of the array is enough to protect the calling code from unexpected changes to the array contents because you are passing "a copy" of the references to things-that-cannot-change... So the callee cannot mutate a pointed-to object, and if the callee changes which object an array element points-to, you won't "see" the change... and of course the callee cannot change which array your reference points to, because Java passes references by value.
    Google all the italic stuff... Sun's stuff is the best, then lookout for IBM's stuff, and most Wikipedia articles are really good (a few not so good).
    HTH. Cheers. Keith.

Maybe you are looking for

  • XSLT Transformation Functions

    Hello, I have a trasnformation and something in this transformation is not logical. why do I have to write after the expression for-each, <item>????         <ROOT>           <LIST>             <xsl:for-each select="/pre:XmlInterchange/pre:Payload/pre

  • Match question. Are deleted songs being streamed to my Mac?

    In an attempt to clean up my Mac, after matching and uploading songs, I deleted songs from my Macbook library. If I play songs randomly, those songs that are not on my Mac still play. Are they being redownloaded or are they streamed?

  • Web Service u0096 IDOC with acknowledgement interface

    hi experts, for this scenario do i need to use ccBPM?? <b><i>Web Service – IDOC with acknowledgement interface.</i></b> because we need response from idoc and idoc supports asynchronous processing.

  • EPMA File Generator not working on ASO database

    Greetings, a colleague of mine is having trouble using file generator in EPMA on an ASO database with MDX formulas. He is getting an error, unrecognized application type Essbase (ASO). He used on 11.1.1.3 and, 11.1.2.2. I know there was a defect in 1

  • Launch time for Creative Cloud will be TODAY at 8:00 PM PDT

    The statement above... has been provided via an on-line response to an Adobe representative. Hopefully, the servers will stand strong for the influx in upgrading to all CC members! Fingers crossed!