Array1 =Array2

I have a very simple question.
I have 2 array of objects.
I do this :
array1 = array2;
Strange thing happens when I set a value to array2[1], the array1[1] will also be updated with the same value automatically.
Why does this happen and how to resolve it.
Please help.
Thanks

by array1=array2, you are assigning two reference pointer to the same object, so when you update array1, it will also update array2
do something like
int array2 [] = new int [SIZE];
for (int i=0;i<array1.length;i++)
array2[i] = array1;
if you are using primitive type array
for reference, you have to make a clone of it and cast it back to your object
array2[i] = (Your object) array1[i].clone();
Jacinle
I have a very simple question.
I have 2 array of objects.
I do this :
array1 = array2;
Strange thing happens when I set a value to array2[1],
the array1[1] will also be updated with the same value
automatically.
Why does this happen and how to resolve it.
Please help.
Thanks

Similar Messages

  • Working of  SUMPRODUCT(array1,array2,array3, ...)

    Dear All,
    I need to Implement equivalent functionality of SUMPRODUCT(array1,array2,array3, ...) of excel .in
    oracle
    Please Try to Provide Some Hint.
    Thanks
    I Value Your Time And Efforts
    Edited by: user13474542 on Dec 21, 2010 2:25 AM
    Edited by: user13474542 on Dec 21, 2010 2:26 AM

    INDIRECT is your friend here.
    B2 contains the SUMPRODUCT formula:
    =SUMPRODUCT(D2:D10,E2:E10)
    B3 contains the same formula, using INDIRECT to construct the two ranges from the contents of cells B1 and C1:
    =SUMPRODUCT(INDIRECT(""&B1),INDIRECT(""&C1))
    Details on INDIRECT (and the other functions supported in Numbers), along with at least one example for each function, may be found in the iWork Formulas and Functions User Guide, which can be downloaded via the Help menu in Numbers '09.
    Also available in the same location is a download link for the Numbers '09 User Guide, a more general guide to the features of Numbers. The first few chapters are strongly recommended as required reading for anyone new to Numbers, and especially to those migrating from another spreadsheet application; the rest may be browsed or devoured when there's a need to know about a specific topic.
    Regards,
    Barry

  • How can I use a variable as an array's name?

    Ok I have several arrays in my code (lets call them "array1", "array2" etc) and I want to load them based on the users input. So if the user enters array1, I want the first array to be loaded, and the same with the other arrays.
    I tried saving the user's input on a string variable called ARRAY_NAME, so that each time the user enters a different array name, the corresponding array is loaded. Something like this:
      ARRAY_NAME[c1][c2]; but I get this error:
    array required, but java.lang.String found
              ARRAY_NAME[c1][c2];
    ___________^
    Can you please tell me what is the correct way of doing it?
    Thanx!

    The short answer is you can't. An object name can't be
    variable and must be known at compile time. But you
    could associate the user input name with a particular
    array, for example, using a HashMap with the user name
    as the key to an array. However, you'd need to use a
    container class (Vector, ArrayList, etc.) rather than
    a raw array, because containers only take class
    instances as elements.Maps can't deal with primitives, that is true. However, arrays are full scale objects, so they can be put into maps.
    Also, my code had a bug in it. Try this:
    int userIndex = getUserIndex();
    String userInput = getUserInput();
    Field array = getClass().getDeclaredField(userInput);
    Object item = Array.get(array.get(this), userIndex);

  • How can I create arrays through the same recursive process?

    Hello again!
    I want to create some arrays with names like array1, array2, array3 etc
    through the same for loop.
    Do you know how this can be done? Thanks!
    for (int i = 0; i < 32; i++) {
    byte[] array???=new byte[400];
    }

    I want to create some arrays with names like array1,
    array2, array3 etc
    through the same for loop.
    Do you know how this can be done? Thanks!
    for (int i = 0; i < 32; i++) {
    byte[] array???=new byte[400]; You cannot create new names during runtime (array1, array2 are names).
    You can create a map that associates Strings with byte arrays though:Map<String, byte[]>  map= new HashMap<String, byte[]>();
    for (int i= 0; i < 32; i++)
       map.put("array"+i, new byte[400]);
    // get array associated with array26:
    int j= 26;
    byte[] oneOfTheArrays= map.get("array"+j);kind regards,
    Jos

  • Transfering elements to new array and doubling values.

    Hi my problem is that I need to ask a user to enter 5 integers that stores them in an array. Transfer them to a new array by doubling the values when trasferred.
    Please help I have 3 errors.
    class arrays
         public static void main (String[] args)
              int numbers[] = new int [5];
              byte array1Size = 0;
              int input = 0;
              char goon = 'y';
                   //create and initialise an array of 5 integers
                   int array1[] = new int [5];
                   // loop and fill each element
                   for (int x = 0; x < array1.length; x++)
                        System.out.println("Enter a number: ");
                        array1[x] = EasyIn.getInt();
                        // Filling array
                        if (array1Size >= array1.length)
                             //Make a new array doubling the values od the integers
                             int array2 [] = new int [2 * array1.length]; // 10 integers
                             //Copying integers
                             System.arrayCopy (array1, 0, array2, 0, array1.length);
                             //Make old reference point to new array
                             array1 = array2;
                        else
                             //normal
                             do
                                  System.out.print("Enter an integer: ");
                                  input = EasyIn.getInt();
                                  anotherArray[anotherArraySize] = input;
                                  anotherArraySize++;
                                  System.out.print ("Another number? Enter Y or N: ");
                                  goon = EasyIn.getChar();
                             }     while(goon = = 'y' | goon = = 'Y');
    the errros >>>
    G:\Java\Practical 7\Practical74.java:33: '.class' expected
                             int array2 [] = new int [2 * array1.length]; // 10 integers
    ^
    G:\Java\Practical 7\Practical74.java:33: not a statement
                             int array2 [] = new int [2 * array1.length]; // 10 integers
    ^
    G:\Java\Practical 7\Practical74.java:41: 'else' without 'if'
                        else
    ^
    3 errors
    Tool completed with exit code 1
    Thanks

    Hi,
    it seems you forgot the curly braces in the if-else statement:
    if (array1Size >= array1.length){
    //Make a new array doubling the values od the integers
    int array2 [] = new int [2 * array1.length]; // 10 integers
    //Copying integers
    System.arrayCopy (array1, 0, array2, 0, array1.length);
    //Make old reference point to new array
    array1 = array2;
    else{
    //normal
    do
    System.out.print("Enter an integer: ");
    input = EasyIn.getInt();
    anotherArray[anotherArraySize] = input;
    anotherArraySize++;
    System.out.print ("Another number? Enter Y or N: ");
    goon = EasyIn.getChar();
    } while(goon = = 'y' | goon = = 'Y');
    }

  • Problem with Webdynpro Tables and Scatter-chart

    I have a Webservice who returns two one-dimensional arrays. I want to know how to fill one table with these arrays. And how to get this data displayed in an two dimensional scatter-chart as x and y Values.

    Create a context node "Rows", cardinality 0:N, add attributes A, B (type as needed e.g. "string").
    Fill the node with the content of your arrays array1, array2 (assuming both arrays have same length):
    for (int j = 0; j < array1.length; ++j)
      IRowElement row = wdContext.nodeRows().createRowsElement();
      wdContext.nodeRows().addElement(row);
      row.setA(array1[j]);
      row.setB(array2[j]);
    Display in a Table: Create a Table T, add columns CA / CB, add to each a TextView as cell editor. Bind cell editor's property "text" to attribute A / B.
    For display in BusinessGraphics element, read the documentation at
    http://help.sap.com/saphelp_nw04/helpdata/en/e5/08b6eb35637a44830b9e6df22987aa/content.htm
    Armin

  • Problems with my matrix...

    Hi,
    I get this error when I try to run through this part of my code:
    "java.lang.NullPointerException"
    What am I doing wrong?
        int counter1=0, counter2=0, sum=0;
        Double temp1, temp2, result;
        Double[] Array1, Array2;
        Double[][] newMatrix, dmatrix;
                while(counter1 < dmatrix.length) {
                for(int i = 0; i < dmatrix[counter1].length; i++) {
                    Array1[i] = dmatrix[counter1]; // <--I believe the errors are here? But it could be due to something else
    System.out.println(Array1[i]);
    counter2 = counter1 + 1;
    while(counter2 < dmatrix.length) {
    for(int j = 0; j < dmatrix[counter2].length; j++) {
    Array2[j] = dmatrix[counter2][j]; // <--I believe the errors are here? But it could be due to something else
    for(int k = 0; k < Array2.length; k++) {
    temp1 = Array1[k];
    temp2 = Array2[k];
    if(temp1.compareTo(temp2) < 0) {
    result = new Double (result.doubleValue() + ( temp1.doubleValue()/temp2.doubleValue() ) );
    else if(temp1.compareTo(temp2) > 0) {
    result = new Double (result.doubleValue() + ( temp2.doubleValue()/temp1.doubleValue() ) );
    sum++;
    System.out.println(result);
    counter1++;
    sum = 0;

    Double[] Array1, Array2;
    Double[][] newMatrix, dmatrix;Wrong. You haven't allocated any memory. Where's the call to new? All you've done is declare variables of a given type.
    You need to do something more like this:
    public class MatrixTester
        public static void main(String [] args)
            int numRows = 5;
            int numCols = 5;
            double [][] matrix = new double[numRows][];
            for (int m = 0; m < numRows; ++m)
                matrix[m] = new double[numCols];
                for (int n = 0; n < numCols; ++n)
                    matrix[m][n] = (double)(m + n);
            for (int m = 0; m < numRows; ++m)
                for (int n = 0; n < numCols; ++n)
                    System.out.print(matrix[m][n] + " ");
                System.out.println();
    }Note the calls to "new".

  • [PS] Multiple array´s split and merge

    Is it possible to: when you have 3 array's split the value's after the comma and then from each array merge every 1st value with 1st, 2 with 2 and so on.
    I know you can use split to split up an array, but i have no clue how to merge it like i want.
    example:
    array 1 :
    1,7,5,0,9,1
    array 2 :
    dog,cow,cat,horse,man,girl
    array 3 :
    short,big,little,huge,long,small
    output 1 :
    1 dog short
    output 2 :
    7 cow big
    output 3 :
    5 cat little
    or even better is that it gonna be variable
    $array1 :
     1,7,5,0,9,1
    $array2 :
     dog,cow,cat,horse,man,girl
    $array3 :
     short,big,little,huge,long,small
    output 1 :  $array1 $array2 $array3
    output 1 :
     1 dog short
    output 2 :  $array1 $array2 $array3
    output 2 :
     7 cow big
    output 3 :  $array1 $array2 $array3
    output 3 :
     5 cat little
    Sincerely,
    Jeroen 

    hi Jeroen,
    sure you can do that. Simply iterate over each index of the arrays:
    $int = 0
    While ($int -lt $array1.Length)
    ($array1[$int] + " " + $array2[$int] + " " + $array3[$int])
    $int++
    Cheers,
    Fred
    There's no place like 127.0.0.1

  • Resizing a window containing a graph

    I have created a class that plots points on a graph using two arrays passed to the class. One array is for the x-values, the other is for the y-values. Initially, the graph is fine. When I minimize or maximize the window, the values in the arrays change and causes the points to disappear. If I restore the window to the original size, the points are still gone. Why are the values in my array changing? Here is the code:
    //Graph_Lin.java
    //Graphs thermodynamic properties
    import java.util.Scanner;
    import java.awt.Graphics;
    import javax.swing.JPanel;
    public class Graph_Lin extends JPanel
      private int x1, y1, x2, y2;
      public double x[], y[];
      public double xpoint[], ypoint[];
      private double xmax = 0;
      private double ymax = 0;
      private double xmin, ymin, xrange, yrange;
      //constructor sets coordinates of axes
      public Graph_Lin( double xdata[], double ydata[] )
        x = xdata;
        y = ydata;
        xpoint = xdata;
        ypoint = ydata;
          xmin = x[0];
          ymin = y[0];
          int j = 0;
          while ( x[j] > 0)
            if ( x[j] > xmax)
           xmax = x[j];
         if ( y[j] > ymax)
             ymax = y[j];
            if ( x[j] < xmin)
           xmin = x[j];
         if ( y[j] < ymin)
             ymin = y[j];
         j++;
          yrange = ymax - ymin;
          xrange = xmax - xmin;
        public void paintComponent( Graphics g )
          super.paintComponent( g );
          x1 = getx1();
          x2 = getx2();
          y1 = gety1();
          y2 = gety2();
          g.drawLine(x1, y1, x2, y1);
          g.drawLine(x1, y1, x1, y2);
    //*****create the points for plotting*************
          int diam = 10;  //diameter of data point in pixels, should be an even number
          for ( int i = 0; i < x.length; i++ )
         xpoint[i] = (x[i]-xmin)/xrange*(x2-x1)+x1 - diam/2;
         ypoint[i] = y1 - (y[i]-ymin)/yrange*(y1-y2) - diam/2;
          for ( int i = 0; i < x.length; i++ )
           g.drawOval( ((int) xpoint),((int) ypoint[i]),diam,diam);
    //*****get values for the x and y axes****************
    public int getx1()
    return x1 = (int) (.05 * getWidth());
    public int gety1()
    return y1 = (int) (.95 * getHeight());
    public int getx2()
    return x2 = (int) (.95 * getWidth());
    public int gety2()
    return y2 = (int) (.05 * getHeight());
    //*****end get values for the x and y axes************

    What is an SSCCE? Here are the other files. I think I got them all.
    //LiquidDensity.java
    //This class calculates and returns density for water vapor
    //First, it calculates specific volume.  Then it returns the reciprocal as density
    public class LiquidDensity
      public double getv(double T)
          double kv = 1;          //kv represents specific volume x 10^3
          double Th, Tl, kh, kl;     //kh is spec vol at Th, kl is spec vol at Tl
         if (T >= 645 && T <= 647.3)
              Th = 647.3;
              Tl = 645;
                kh = 3.170;
              kl = 2.351;
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 640 && T <= 645)
              Tl = 640;
              Th = Tl+5;
                kl = 2.075;
              kh = 2.351;
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 635 && T <= 640)
              Tl = 635;
              Th = Tl+5;
                kl = 1.935;
              kh = 2.075;
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 630 && T <= 635)
              Tl = 630;     //mod
              Th = Tl+5;
                kl = 1.856;     //mod
              kh = 1.935;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 625 && T <= 630)
              Tl = 625;     //mod
              Th = Tl+5;
                kl = 1.778;     //mod
              kh = 1.856;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 620 && T <= 625)
              Tl = 620;     //mod
              Th = Tl+5;
                kl = 1.705;     //mod
              kh = 1.778;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 610 && T <= 620)
              Tl = 610;     //mod
              Th = Tl+10;
                kl = 1.612;     //mod
              kh = 1.705;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 600 && T <= 610)
              Tl = 600;     //mod
              Th = Tl+10;
                kl = 1.541;     //mod
              kh = 1.612;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 590 && T <= 600)
              Tl = 590;     //mod
              Th = Tl+10;
                kl = 1.482;     //mod
              kh = 1.541;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 580 && T <= 590)
              Tl = 580;     //mod
              Th = Tl+10;
                kl = 1.433;     //mod
              kh = 1.482;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 570 && T <= 580)
              Tl = 570;     //mod
              Th = Tl+10;
                kl = 1.392;     //mod
              kh = 1.433;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 560 && T <= 570)
              Tl = 560;     //mod
              Th = Tl+10;
                kl = 1.355;     //mod
              kh = 1.392;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 550 && T <= 560)
              Tl = 550;     //mod
              Th = Tl+10;
                kl = 1.323;     //mod
              kh = 1.355;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 540 && T <= 550)
              Tl = 540;     //mod
              Th = Tl+10;
                kl = 1.294;     //mod
              kh = 1.323;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 530 && T <= 540)
              Tl = 530;     //mod
              Th = Tl+10;
                kl = 1.268;     //mod
              kh = 1.294;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 520 && T <= 530)
              Tl = 520;     //mod
              Th = Tl+10;
                kl = 1.244;     //mod
              kh = 1.268;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 510 && T <= 520)
              Tl = 510;     //mod
              Th = Tl+10;
                kl = 1.222;     //mod
              kh = 1.244;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 500 && T <= 510)
              Tl = 500;     //mod
              Th = Tl+10;
                kl = 1.203;     //mod
              kh = 1.222;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 490 && T <= 500)
              Tl = 490;     //mod
              Th = Tl+10;
                kl = 1.184;     //mod
              kh = 1.203;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 480 && T <= 490)
              Tl = 480;     //mod
              Th = Tl+10;
                kl = 1.167;     //mod
              kh = 1.184;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 470 && T <= 480)
              Tl = 470;     //mod
              Th = Tl+10;
                kl = 1.152;     //mod
              kh = 1.167;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 460 && T <= 470)
              Tl = 460;     //mod
              Th = Tl+10;
                kl = 1.137;     //mod
              kh = 1.152;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 450 && T <= 460)
              Tl = 450;     //mod
              Th = Tl+10;
                kl = 1.123;     //mod
              kh = 1.137;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 440 && T <= 450)
              Tl = 440;     //mod
              Th = Tl+10;
                kl = 1.110;     //mod
              kh = 1.123;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 430 && T <= 440)
              Tl = 430;     //mod
              Th = Tl+10;
                kl = 1.099;     //mod
              kh = 1.110;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 420 && T <= 430)
              Tl = 420;     //mod
              Th = Tl+10;
                kl = 1.088;     //mod
              kh = 1.099;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 410 && T <= 420)
              Tl = 410;     //mod
              Th = Tl+10;
                kl = 1.077;     //mod
              kh = 1.088;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 400 && T <= 410)
              Tl = 400;     //mod
              Th = Tl+10;
                kl = 1.067;     //mod
              kh = 1.077;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 390 && T <= 400)
              Tl = 390;     //mod
              Th = Tl+10;
                kl = 1.058;     //mod
              kh = 1.067;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 385 && T <= 390)
              Tl = 385;     //mod
              Th = Tl+5;
                kl = 1.053;     //mod
              kh = 1.058;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 380 && T <= 385)
              Tl = 380;     //mod
              Th = Tl+5;
                kl = 1.049;     //mod
              kh = 1.053;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 375 && T <= 380)
              Tl = 375;     //mod
              Th = Tl+5;
                kl = 1.045;     //mod
              kh = 1.049;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 373.15 && T <= 375)
              Tl = 373.15;     //mod
              Th = 375;
                kl = 1.044;     //mod
              kh = 1.045;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         else if (T >= 370 && T <= 373.15)
              Tl = 370;     //mod
              Th = 373.15;
                kl = 1.041;     //mod
              kh = 1.044;     //mod
              kv = (((kh-kl)/(Th-Tl))*(T-Th)+kh)*Math.pow(10, -3);
         return 1/kv;          //returns liquid density for specified temperature
    }Next file
    //A Test program
    //John Abbitt
    //November 29, 2006
    import javax.swing.JFrame;     //import class JOptionPane
    public class Test
      public static void main( String args[] )
        double array1[] = new double[200];
        double array2[] = new double[200];
        LiquidDensity dl = new LiquidDensity();
        //Conductivity c = new Conductivity();
        //SpecificVolumeG g = new SpecificVolumeG();
        double T = 370;
        for (int i = 0; i <56; i++)
          array1[i] = T;
          array2[i] = dl.getv(T)  ;
          T=T+5;
        //Test the graph
        JTabbedPaneSetUp application = new JTabbedPaneSetUp(array1, array2);
        application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        application.setSize( 400, 400 );
        application.setVisible( true );
    }Next file
    //A Test program
    //John Abbitt
    //November 29, 2006
    import javax.swing.*;     //import class JOptionPane
    public class JTabbedPaneSetUp extends JFrame
      public double x[], y[];
      public JTabbedPaneSetUp(double array1[], double array2[])
        super( "Graph Program" );
        x = array1;
        y = array2;
        Graph_Lin graph1 = new Graph_Lin(x, y);
        Graph_Log graph2 = new Graph_Log(x, y);
        JTabbedPane tabbedPane = new JTabbedPane();
        //set up panel1 and add it to JTabbedPane
        JPanel panel1 = new JPanel();
        tabbedPane.addTab( "Linear", null, graph1, "Displays a liner graph");
        //set up panel2 and add it to JTabbedPane
        JPanel panel2 = new JPanel();
        tabbedPane.addTab( "Semi-log", null, graph2, "Displays a semi-log graph");
        add( tabbedPane );
    }

  • Compare 2 Arrays??

    Hi,
    I'm looking for a easy way to compare 2 arrays and get an result. We take one on we have in the first array the values 1, 2, 3, 4 and 5 and in the second array we have the values 3 and 5.
    array1 | array2
    1 | 3
    2 | 5
    3 |
    4 |
    5 |
    After comparing I should get as result jus the values 1,2 and 4. I already searched for a solution but i couldn't find anything. Except a way, that I think would be quite complex.
    My Solution ->
    First I read out both arrays and try to save them in a collection (HashSet) type. Then it will be possible to use the method removeAll() of the interface Set. The result should again be converted to an array.
    Does anyone know an easier way? Thx!
    Cyrill

    Why is using a Set so hard? That seems like the best way to me. The "hard" part would only be if you're filling the set with a loop instead of the easy way:
    Set set = new HashSet(Arrays.asList(yourArray));
    set.removeAll(Arrays.asList(yourOtherArray));How can it get easier than 2 lines of code?

  • Need help with some code ... Searching a tree and inserting data

    I'm trying to write code for the addIterative method below.
    My problem is that I also need to search the list or node to see if the word exists.
    The method add(word,line,position,iterative) validates the parameters; and, in order to update the tree and/or any relevant linked-list, calls either the incomplete method addIterative(word,line,position) or the incomplete method addRecursive(word,line,position). Note the following: if the word is not contained currently in the tree, then all of the (word,line,position) triplet needs to be added to the data structure; otherwise, only the (line,position) pair needs to be added to the data structure. The result must be the same regardless of the algorithmic strategy employed.
    any suggestions would be greatly appreciated, new to java, and very lost.
    regards,
    Jimmy
    * Write a description of class Tree091 here.
    * @author (your name)
    * @version (a version number or a date)
    class Tree091 /*(i.e., WordTree)*/
    { private char[] word=null;
    private List091 list=null;
    private Tree091 precursor=null; /*(i.e., leftSubTree)*/
    private Tree091 successor=null; /*(i.e., rightSubTree)*/
    public Tree091(char[] word,
    List091 list,
    Tree091 precursor, /*(i.e., lexicographically < word)*/
    Tree091 successor) /*(i.e., lexicographically > word)*/
    { if (word==null) return;
    if (word.length<1) return;
    if (list==null) return;
    this.word=word;
    this.list=list;
    this.precursor=precursor;
    this.successor=successor;
    public void add(char[] word,
    int line,
    int position,
    boolean iterative)
    { if (word==null) return;
    if (word.length<1) return;
    if (line<0) return;
    if (position<0) return;
    if (iterative)
    this.addIterative(word,line,position);
    else
    this.addRecursive(word,line,position);
    private void addIterative(char[] word,
    int line,
    int position)
    /* something goes here*/
    private void addRecursive(char[] word,
    int line,
    int position)
    /* something goes here*/
    private int compare(char[] array1,
    char[] array2)
    { if (array1==null) return -2;
    if (array2==null) return -2;
    int length1=array1.length;
    if (length1==0) return -2;
    int length2=array2.length;
    if (length2==0) return -2;
    int minLength=length1<length2?length1:length2;
    for (int i=0; i<minLength; i++)
    { if (array1[i]<array2) return -1;
    if (array1[i]>array2[i]) return 1;
    return length1==length2 ? 0 : length1<length2 ? -1 : 1;
    public boolean contained(char[] word)
    { int compare=compare(this.word,word);
    if (compare==1&&this.precursor!=null)
    return this.precursor.contained(word);
    if (compare==0) return true;
    if (compare==-1&&this.successor!=null)
    return this.successor.contained(word);
    return false;
    public int listNodeCount(boolean iterative)
    /* something goes here*/
    return 24;
    public int maximumWordLength(int currentLength)
    /* something goes here*/
    return 25;
    public String toString()
    { String string="";
    if (this.precursor!=null) string+=this.precursor;
    string+="\""+(new String(this.word))+"\""+this.list;
    if (this.successor!=null) string+=this.successor;
    return string;
    public int treeNodeCount()
    /* something goes here*/
    return 26;
    public String wordArray(int length)
    /* something goes here*/
    return "hey hey wordarray";

    hey,
    ok, wow, that was intense, my brain hurts!!!!
    And now I've got to go do a graduate program test, argh!!!
    A problem I keep getting is trying to figure out what my lecturer is doing in the start of the Tree091 class,
    that is, I can see that he is constructing the list and tree but it appears that he is doing it all at the same time, and I'm getting confused with what actually gets inserted into the list, and do we insert the word, line and position, or just the line and position?
    Also, I didnt use a 'while loop', I'm not sure how, but I found a 'for loop' in the text book, what do you think of it? Is it ok for now?
    And I'm getting an error at this line:
    Tree091 ins = new Tree091(char[] word); // getting error '.class' expected here
    any ideas?
    heres what I've got so far:
    private void addIterative(Comparable char[] word,int line, int position){
    // Insert char[] word into the this BST     
         int direction = 0;     
         Tree091 parent = null, curr = root;
         for (;;) {     
              if (curr == null) {
                   Tree091 ins = new Tree091(char[] word); // getting error '.class' expected here
                   // word found so we call insertList method
                   insertList091(line, position, List091 precursor);
                   if (root) == null)
                        root = ins;
                   else if (direction < 0)     
                        parent.left = ins;
                   else // direction > 0
                        parent.right = ins;
                   return;
              direction = elem.compareTo(curr.element);
              if (direction == 0)
                   return;
              parent = curr;
              if (direction < 0)
                   curr = curr.left;
              else // direction > 0
                   curr = curr.right;
    }And heres an attempt at the insertList method
    private void insertList(char[] word, int line, int position, List091 precursor){
    // Insert line and position at a given point in this List091, either after the node
    // precursor, or before the first node if precursor is null
    // Looking at assignment question we may need a double linked list
         List091 ins = new List091 (char[] word, line, position, null);
         if precursor == null) { //insert before first node (if any).
              ins.successor = first;
              first = ins;
         } else {
              ins.successor = precursor.successor;
              precursor.successor = ins;
    }How far off am I Joachim?
    cheers,
    Jimmy
    ps. heres the tree091 class again:
    class Tree091 /*(i.e., WordTree)*/
    { private char[] word=null;
      private List091 list=null;
      private Tree091 precursor=null; /*(i.e., leftSubTree)*/
      private Tree091 successor=null; /*(i.e., rightSubTree)*/
      public Tree091(char[] word,
                     List091 list,
                     Tree091 precursor, /*(i.e., lexicographically < word)*/
                     Tree091 successor) /*(i.e., lexicographically > word)*/
      { if (word==null) return;
        if (word.length<1) return;
        if (list==null) return;
        this.word=word;
        this.list=list;
        this.precursor=precursor;
        this.successor=successor;
      public void add(char[] word,
                      int line,
                      int position,
                      boolean iterative)
      { if (word==null) return;
        if (word.length<1) return;
        if (line<0) return;
        if (position<0) return;
        if (iterative)
          this.addIterative(word,line,position);
        else
          this.addRecursive(word,line,position);
      private void addIterative(char[] word,
                                int line,
                                int position)
        /* students to complete */
      private void addRecursive(char[] word,
                                int line,
                                int position)
         /* students to complete */
      private int compare(char[] array1,
                          char[] array2)
      { if (array1==null) return -2;
        if (array2==null) return -2;
        int length1=array1.length;
        if (length1==0) return -2;
        int length2=array2.length;
        if (length2==0) return -2;
        int minLength=length1<length2?length1:length2;
        for (int i=0; i<minLength; i++)
        { if (array1<array2[i]) return -1;
    if (array1[i]>array2[i]) return 1;
    return length1==length2 ? 0 : length1<length2 ? -1 : 1;
    public boolean contained(char[] word)
    { int compare=compare(this.word,word);
    if (compare==1&&this.precursor!=null)
    return this.precursor.contained(word);
    if (compare==0) return true;
    if (compare==-1&&this.successor!=null)
    return this.successor.contained(word);
    return false;
    public int listNodeCount(boolean iterative)
    /* students to complete */
    public int maximumWordLength(int currentLength)
    /* students to complete */
    public String toString()
    { String string="";
    if (this.precursor!=null) string+=this.precursor;
    string+="\""+(new String(this.word))+"\""+this.list;
    if (this.successor!=null) string+=this.successor;
    return string;
    public int treeNodeCount()
    /* students to complete */
    public String wordArray(int length)
    /* students to complete */
    Edited by: allergy01 on Apr 25, 2009 9:19 PM
    Edited by: allergy01 on Apr 25, 2009 9:20 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • SUMPRODUCT dynamic range

    I wanted to do some number cruching in Numbers with quite a few formulas like (SUMPRODUCT(array1, array2) + SUMPRODUCT(array3, array4)) / SUM(array5) for every worksheet, which is fine except that I've got some ten worksheets. And each worksheet is a bit different in terms of array sizes and locations.
    It'd be more efficient (and less error-prone) if I could get to write generic formulas and let each worksheet derive the final 'array's by referring to values stored in certain cells. Basically make it table-driven formulas if you know what I mean.
    Unfortunately Numbers returns error for say SUMPRODUCT(B2), where the B2 cell has a string like "D10:D144, R10:R144". So it appears Numbers won't happily take Text value for Range value.
    I've checked some online forum. Some mentioned using INDIRECT or INDEX, and my trial result still returned error. Others mentioned table names or VB object attributes (which sound like Excel-only).
    Wondering if anyone ran into similar situation and got answers? It'd be great to be able to learn and move on and not getting stuck here.

    INDIRECT is your friend here.
    B2 contains the SUMPRODUCT formula:
    =SUMPRODUCT(D2:D10,E2:E10)
    B3 contains the same formula, using INDIRECT to construct the two ranges from the contents of cells B1 and C1:
    =SUMPRODUCT(INDIRECT(""&B1),INDIRECT(""&C1))
    Details on INDIRECT (and the other functions supported in Numbers), along with at least one example for each function, may be found in the iWork Formulas and Functions User Guide, which can be downloaded via the Help menu in Numbers '09.
    Also available in the same location is a download link for the Numbers '09 User Guide, a more general guide to the features of Numbers. The first few chapters are strongly recommended as required reading for anyone new to Numbers, and especially to those migrating from another spreadsheet application; the rest may be browsed or devoured when there's a need to know about a specific topic.
    Regards,
    Barry

  • Trouble with sending huge arrays via DataSocket​s.

    Hi,
    I am having trouble sending huge arrays via Data Sockets from my main vi on the server PC to the vi on the client PC.
    To further elaborate, in my main vi program I have created 3 arrays called Array1, Array2 and Array3 on my front Panel. By right clicking the mouse on each set of array and from the pop-up menu I selected Data Operations-> DataSocket Connection and I entered dstp://localhost/Array1 and clicked on Publish to broadcast the data from Array1. Similarly, I did the same for Array2 and Array3.
    Now, in my client vi program I have created three arrays on my front Panel to read (Subscribe) the data from the three arrays broadcasted via DataSockets from the server’s main vi program. To subsc
    ribe the data I did the similar process above and clicked on Subscribe to read the data (of course the IP address of the client PC will be different then the server PC so enter the hosts IP address). Once the data is received in the client arrays, I am using LV2 globals so that I can use these arrays on other sub-vi’s locally (instead of having each sub-vi get data from the server directly).
    I succeeded in doing this with two arrays, however when I added the third array the DataSockets would not work consistently. For example the refresh rate would get slower at times and sometimes 2 out of the 3 arrays would update. I don’t know if I have exceeded the limit on how much data DataSockets can broadcast, but I need to have some mechanism to broadcast 6 arrays (approx. 10000 elements for each array) of double digits precision.
    Has anyone come across this issue? Is there another way of broadcasting data more efficiently then DataSockets?
    I would appreciate any
    help that I can get.
    I have attached the files for this program in the zip file.
    First run the Server main program, testServeMainVI.vi, and then the client program, testClientMainVI.vi.
    Thanks
    Nish
    Attachments:
    beta2.zip ‏70 KB

    DataSocket can be a lossy communication. I like the advice to flatten the data to a string, but another option would be to buffer the communcation. The problem might be that the data is being overwritten on the server faster than it is being read. There is an example of buffered datasocket on NI web page: http://venus.ni.com/stage/we/niepd_web_display.DIS​PLAY_EPD4?p_guid=BA3F9DFED17F62C3E034080020E74861&​p_node=DZ52000_US&p_submitted=N&p_rank=&p_answer=&​p_source=Internal
    Also, I have played with the new built in buffered datasocket in LabVIEW 7.0. It is pretty slick. If buffers the data both on the server and the client side.

  • Strange Compiler Error

    Hi, I was wondering if you could help me out with a little problem that I've encountred. When I compile my project, I get the following errors:
    Errors:
    C:\Program Files\Xinox Software\JCreatorV3 LE\MyProjects\MatrixAddition\MatrixAddition.java:23: illegal start of type
            while(exit == false) {
            ^
    C:\Program Files\Xinox Software\JCreatorV3 LE\MyProjects\MatrixAddition\MatrixAddition.java:120: <identifier> expected
    ^
    2 errorsRadReader class:
    import java.io.*;
    import java.lang.*;
    // Use to throw exceptions
    class RadReaderException extends RuntimeException { 
         RadReaderException(Throwable cause) {   
              super(cause); 
    public class RadReader {       
         public static int readInt(String prompt) {          
         BufferedReader bfRdr = new BufferedReader(new InputStreamReader(System.in));
              // Print the prompt
              if(prompt != "") {
                   System.out.print(prompt);
              // Get string input
              int integer = 0;
              String input = "";
              try {
                   input = bfRdr.readLine();
              catch(IOException e) {
                   throw new RadReaderException(e);
              // Convert to int
              try {
                   integer = Integer.parseInt(input);
              catch(NumberFormatException e) {
                   throw new RadReaderException(e);
              // Return integer
              return integer;
         public static float readFloat(String prompt) {          
         BufferedReader bfRdr = new BufferedReader(new InputStreamReader(System.in));
              // Print the prompt
              if(prompt != "") {
                   System.out.print(prompt);
              // Get string input
              float floatingPt = 0;
              String input = "";
              try {
                   input = bfRdr.readLine();
              catch(IOException e) {
                   throw new RadReaderException(e);
              // Convert to float
              try {
                   floatingPt = Float.parseFloat(input);
              catch(NumberFormatException e) {
                   throw new RadReaderException(e);
              // Return floatingPt
              return floatingPt;
         public static double readDouble(String prompt) {          
         BufferedReader bfRdr = new BufferedReader(new InputStreamReader(System.in));
              // Print the prompt
              if(prompt != "") {
                   System.out.print(prompt);
              // Get string input
              double dble = 0;
              String input = "";
              try {
                   input = bfRdr.readLine();
              catch(IOException e) {
                   throw new RadReaderException(e);
              // Convert to double
              try {
                   dble = Double.parseDouble(input);
              catch(NumberFormatException e) {
                   throw new RadReaderException(e);
              // Return dble
              return dble;
         public static char readChar(String prompt) {          
         BufferedReader bfRdr = new BufferedReader(new InputStreamReader(System.in));
              // Print the prompt
              if(prompt != "") {
                   System.out.print(prompt);
              // Get char
              char character = '?';
              try {
                   character = (char)bfRdr.read();
              catch(IOException e) {
                   throw new RadReaderException(e);
              // Return true if method worked
              return character;
         public static char[] readCharArray(String prompt, int length) {
         BufferedReader bfRdr = new BufferedReader(new InputStreamReader(System.in));
              // Print the prompt
              if(prompt != "") {
                   System.out.print(prompt);
              // Get char[]
              char[] array = new char[length];
              try {
                   bfRdr.read(array, 0, array.length);
              catch(IOException e) {
                   throw new RadReaderException(e);
              // Return true if method worked
              return array;
         public static String readString(String prompt) {        
         BufferedReader bfRdr = new BufferedReader(new InputStreamReader(System.in));     
              // Print the prompt
              if(prompt != "") {
                   System.out.print(prompt);
              // Get string input
              String string = "";
              try {
                   string = bfRdr.readLine();
              catch(IOException e) {
                   throw new RadReaderException(e);     
              // Return true if method works
              return string;
    }Main(Matrix Addition):
    public class MatrixAddition {
         // Radreader object
         RadReader reader = new Radreader();
         // Instantiate arrays
         int[][] array1 = new int[3][2];
         int[][] array2 = new int[3][2];
         int[][] array3 = new int[3][2];
         // Boolean control variables
         boolean exit = false;
         // Begin while loop
         while(exit == false) {
              // Get user input
              for(int row = 0; row < array1.length; row++) {
                   for(int column = 0; column < array1[0].length; column++) {
                        // local storage
                        int element = 0;
                        // Query for input
                        element = reader.readInt("Please enter the value of the " +
                                                       "element at row " + row + " and " +
                                                       "column " + column + ":");
                        // Set input to array1
                        array1[row][column] = element;
              // Get user input
              for(int row = 0; row < array2.length; row++) {
                   for(int column = 0; column < array2[0].length; column++) {
                        // local storage
                        int element = 0;
                        // Query for input
                        element = reader.readInt("Please enter the value of the " +
                                                       "element at row " + row + " and " +
                                                       "column " + column + ":");
                        // Set input to array1
                        array2[row][column] = element;
              // Add arrays
              for(int row = 0; row < array3.length; row++) {
                   for(int column = 0; column < array3[0].length; column++) {
                        // Set input to array1
                        array3[row][column] = array1[row][column] +array2[row][column];
              // Print arrays
              System.out.println("Array 1");
              for(int row = 0; row < array1.length; row++) {
                   for(int column = 0; column < array1[0].length; column++) {
                        System.out.print(array1[row][column] + " ");
                   System.out.println();
              System.out.println();
              System.out.println("Plus");
              System.out.println();
              System.out.println("Array 2");
              for(int row = 0; row < array2.length; row++) {
                   for(int column = 0; column < array2[0].length; column++) {
                        System.out.print(array2[row][column] + " ");
                   System.out.println();
              System.out.println();
              System.out.println("Equals");
              System.out.println();
              for(int row = 0; row < array3.length; row++) {
                   for(int column = 0; column < array3[0].length; column++) {
                        System.out.print(array3[row][column] + " ");
                   System.out.println();
              // Check for exit flag
              char exitFlag = reader.readChar("Quit?(y/n) ");
              if(exitFlag == 'y' || exitFlag == 'Y') {
                   exit = true;
              System.out.println();          
    }Please advize me on how to fix my code.
    Thanks!

    Nothing strange. You can only write a statement (such as a while-loop) inside a block. You can only write a block inside a method declaration or initializer.
    Your problem is that you put the while-loop straight inside a class declaration. You should put it inside a method instead.

  • ライブラリ関数呼び出しノードについて

    お世話になっております。
    外部DLLをC++で作成し、LabVIEWで読み込む工程を作ろうとしています。
    ライブラリ関数呼び出しノードを配置後、パラメータを作成しています。このパラメータは渡しも返りも二次元配列にしたいのですが、
    「.cファイルを作成」で.cを作成してみると、ヘッダの宣言は
    void Sfunc(double X[], double Y[])になっています。何故、二次元を指定しているにも関わらず1次元配列を宣言するのでしょうか?
    ここで一次元配列のままである為か、その後DLLを参照しVIを実行すると
    「呼び出された外部コードで例外が起きました 」とエラーが発生致します。
    原因を教えて頂ければ幸いです。
    以上宜しくお願い致します。
    解決済!
    解決策の投稿を見る。

    5343eddy様
    DLL を使う言語が LabVIEW だけなら配列ハンドルポインタを使えば、二次元配列を含む構造体のデータを引き渡すことができます。
    しかし、他言語でも使われる DLL では配列データポインタを使った方が DLL としての汎用性が高まります。
    私は、LabVIEW だけではなく、Visual Basic や C++, C言語でもアクセスできる DLL を使う必要があるため、配列データポインタを使っています。
    配列ハンドルポインタを使うと、Visual Basic でどう安全に構造体の数値をやり取りするか問題となるためです。
    具体的には、Visual C++ で DLL を作成しておりますが、C言語でもアクセスできるように、まず DLL の関数は extern "C"  を宣言して C言語の関数として作ります。
    そして二次元配列を渡す時にポインタとして渡します。その際、DLL 側は配列の行列の次元数を知りようがないので、次元数を引数として DLL 関数に渡せるようにします。
    具体的なコード例は以下のような感じです。
    今、環境のない場所にいるので、実際の LabVIEW プログラムで提案はできませんが、ご参考までに。
    #ifdef __cplusplus
    extern "C"{
    #endif
    _declspec (dllexport) void Sfunc
        double *IM1,
        double *ii,
        int column_size,
        int row_size,
        int N,
        int M
    #ifdef __cplusplus
    #endif
    _declspec (dllexport) void Sfunc
        double *IM1,
        double *ii,
        int column_size, /* 行サイズとして 500 を渡す */
        int row_size,   /* 列サイズとして 500 を渡す */
        int N,   /* N として 240 を渡す */
        int M   /* M として 320 を渡す */
        double isxy;
        int i;
        int j;
        *(ii+0*row+0) = *(IM1+0*row+0);
        for (j=1; j<M; j++) {
            *(ii+0*row+j) = *(ii+0*row+(j-1)) + *(IM1+0*row+j);
        for (i=1; i<N; i++) {
         isxy = 0;
            for (j=0; j<M; j++) {
                isxy = isxy + *(IM1+i*row+j);
                *(ii+i*row+j) = *(ii+(i-1)*row+j) + isxy;
    DLL 関数を使う時は次のような引数で呼び出す。
        Sfunc(array1, array2, 500, 500, 240, 300);
    array1, array2 はarray1[ ], array2[ ] のように2次元配列として確保したデータ。

Maybe you are looking for

  • BACKGROUND  SCHEDULING  based on a event

    Hi,     I need to execute my program in background ..  based on an event..for example.. here i want to execute   RBDMIDOC program  based on  when ever i change the master data ..   i created a varient in SE38.. and i enetred into SM37  and  here  wha

  • Recycle Bin

    In Oracle 10g which tablespace does DBA_RECYCLEBIN uses?

  • Trouble downloading Camera Raw 8.1

    When I try to update my Camera Raw version from 7.4 to 8.1 ( I'm running CS6 and LR5) I get a message that I have no new updates to install.  When I open an image from Bridge into CR it clearly shows that I'm running the 7.4 version.  Of course I'm h

  • Front Row Movie Trailers don't work on Airport Network

    I can't view Front Row movie trailers when using an airport network. However, I can see the movies if I bypass the Airport Base Station and connect my iMac straight to my DSL modem via ethernet. I can access all other internet services via Airport -

  • Just uploaded apps from iPhone to Mac Pro but i can't open apps on mac pro?

    Just uploaded apps from iphone to Mac pro but i can't open the apps - Why?