Double array

Is there double array in java? If I want to create a list, and each element in the list is another list, how can I implement this?
Sorry for posting these kinds of questions, but I can't seem to find the correct place to for such things.
Thx

http://java.sun.com/docs/books/tutorial/java/data/multiarrays.html
- Mr K

Similar Messages

  • How can I use a 1 double array for this

    I would like to use one double array where I am using 2 single arrays, can this be done?
    thanks
    import java.text.NumberFormat;
    import java.util.Locale;
    class Mortgage3
              public static void main(String[]argv)
              //Variables
              //allows for currency format
              NumberFormat formatter = NumberFormat.getCurrencyInstance(Locale.US);
              double prin;                              
              double month_payments;
              double monthlyinterest;   
                    //standard integer
              int months;     
                    //array for the different interest rates
                    double[] interest = {0.0535,0.055,0.0575};
              //array for the different terms
                    int[] term = {7, 15, 30};
                    for (int i = 0; i < 3; i++)
              //values for the variables
              prin = 200000;        //principle amount of the mortgage
                    monthlyinterest = (interest[i] / 12);          //monthly interest
              months = (term[i] * 12);               //total amount of months in the 30 yr term
              //monthly payment calculation
              month_payments = (prin * monthlyinterest) / (1-Math.pow(1 + monthlyinterest, - months));           
              System.out.println("\n\n\t For a loan amount of " + formatter.format(prin));
              System.out.println("\t With an annual interest rate of " +interest[i] * 100+ "%,");
              System.out.println("\t your payments will be " +formatter.format(month_payments)+ " per month");
                    System.out.println("\t for a term of "+term[i]+ " years or " +months+" months.");
    }

    I would like to use one double array where I am using 2 single arrays, can this be done?It can, but why not write a Rate class or other data structure more suited to the purpose?

  • Error in converting double to double array

    Iam getting a problem while coverting the values of a table to double array local variable . while the values r getting from the resultset using while(rs.next())
    all the values have to store in the double array.please give me solution to this problem.

    Show us your code and the problem you are facing.

  • Most efficient way to strip nulls from a Double[] array?

    I'm trying to optimize performance of some code that needs to accept a Double[] array (or a List<Double>) and fetch the median of the non-null values. I'm using org.apache.commons.math.stat.descriptive.rank.Median to fetch the median after converting to double[]. My question is how I can most efficiently make this conversion?
    public class MathStatics {
         private static Median median = new Median();
         public static Double getMedian(Double[] doubles) {
              int numNonNull = 0;
              for (int i = 0; i < doubles.length; i++) {
                   if (doubles[i] != null) numNonNull++;
              double[] ds = new double[numNonNull];
              for (int i = 0; i < doubles.length; i++) {
                   if (doubles[i] != null) ds[i] = doubles;
                   System.out.println(ds[i]);
              return median.evaluate(ds);
         public static void main(String[] args) {
              Double[] test = new Double[] {null,null,-1.1,2.2,5.8,null};
              System.out.println(MathStatics.getMedian(test));
    I'm sure that the code I wrote above is clunky and amateurish, so I'd really appreciate some insight into how to make improvements. FWIW, the arrays will typically range in size from ~1-15,000 doubles.
    Thanks!

    There's no need to loop over the array twice
              int numNonNull = 0;
              double[] ds = new double[numNonNull];
              for (int i = 0; i < doubles.length; i++) {
                   if (doubles[i] != null) {
    numNonNull++;
    ds[i] = doubles;
                   System.out.println(ds[i]);
    Except that ds will have length zero, so you'll get a OutOfBoundsException every time you use it.
    As you're using Doubles rather than doubles, you can add the non-null values to an ArrayList and then convert it to an array at the end.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Converting Object Arrat to double array

    public double average(Object ... object)
              double avg=0;
              int count=1;
              for (double d: object)
                   count++;
                    avg +=d;
              return (avg/count);
         }I wanted this code to get compiled with out making much changes(I do not want to change the parameter type of the method).I am gonna pass a double array as an argument to this method.And how could I test that the argument is a double array.

    Pravin
    I don't know if this is exactly what you want, but it is as close as I could make it to your post, and it compiles.    public double average(Object ... objects) {
            double avg = 0;
            int count = 1;
            for (Object d : objects) {
                count++;
                try {
                    avg += (Double) d;
                } catch (java.lang.ClassCastException e) {
                    System.out.println(e.toString());
                    System.out.println("Element No." + count +
                            "is not a valid double.");
            return (avg / count);
        }Please elaborate if you need something more.
    db

  • Vectors : Converting to double[ ] array

    Hello,
    I have a vector which I know consists of double values only. I am trying to create an array of double from this vector but am having some difficulty.
    Firstly if I try this :
    double[] high = (double[])datavector.high.toArray(new double[0]);JBuilder reports :
    'Cannot find method toArray(double[])'
    But if I try this :
    Double[] high = (Double[])datavector.high.toArray(new Double[0]);It works.
    So from this I assume 'Double' is not equal to 'double'
    The trouble is I require 'double[ ]' and NOT 'Double [ ]'.
    Casting Double as (double) does not work... so how do I get double[] from my original vector ?
    Many thanks
    Kerry

    double[] d = new double[v.size()];
              int i = 0;
              for(Iterator<Double> it = v.iterator(); it.hasNext();)
                   d[i++] = (double)it.next();
              just declare the double array to be the size of the vector, then loop thru and populate the array one at a time
    ~Tim

  • Howto when i have very very large double array

    I have code my program about document retrieval.
    I create double array in size [10000]x[8000] for keep value for calculte someting in only memory (about metrix operation).
    I have set parameter to heap memory size at 1024m but it not enough, it has exception out of memory.
    I use Notebook that have RAM 1G. Is this cause for exception?
    Please help me to lead solution for my case.
    Thank you.

    anurag.kapur wrote:
    A couple of points:
    1. Your notebook has 1 GB of RAM and you are allocating 1024 MB (=1 GB) to the JVM heap, which is not possible, as you need some space for running various other Operating System processes as well.This is a good point. There are also things in the JVM itself other than the Java object heap that need space. Thread stacks, loaded classes, native libraries, etc.
    2. Why have you allocated 1024 MB to the JVM heap? Did you choose any random number (obviously with some degree of educated guess)?
    Your array size is 10000 * 8000 = 8 * 10^7
    Thus total heap memory required = 8 * 10^7 * 4 Bytes [The int data type is a 32-bit signed two's complement integer]
    = 320 * 10^6 Bytes
    = 320 MBExcept that peterdog1234 said that the array was an array of doubles, at 8 bytes each, so about 640MB are needed for the array. If the algorithms allow the loss of range and precision, maybe the array could be an array of floats, not doubles. That would keep the array in about 320MB. That would help with the space requirements, but might be slower as all the operations will have to expand the floats to be operated on as doubles, then converted back to floats for storage in the array. But on some architectures that's not too bad.
    I would use -XX:+PrintGCDetails to see how the heap has been partitioned into young generation (fast allocation and collection) and old generation (relatively long-lived data). You might have to reshape the heap to have at least 640MB in the old generation, and then whatever you can fit as the young generation, leaving some of your 1GB for the rest of the JVM, other programs running on the box, the operating system, etc. Maybe "-Xms768m -Xmx768m -XX:NewSize=64m -XX:MaxNewSize=64m" would be a good compromise. That gives you a 768MB Java object heap, with 64MB in the young generation and 704MB in the old generation, leaving 256MB (1GB-768MB) for "other things". Whether that works depends on now many other long-lived Java objects you have. But -XX:+PrintGCDetails will tell you that, too.

  • For dynamically allocated double arrays, sizeof() does not work

    For a typical double array, if you need to get the size, you would use
    numElems=(sizeof(myArray)/sizeof(myArray[0]));
    However, for dynamically allocated double arrays (see here for example) this no longer works.
    For the example above, sizeof(myArray) returns 4, and sizeof(myArray[0]) returns 8.
    Solved!
    Go to Solution.

    That's because sizeof(myArray) is the size of the pointer to the dynamically allocated array.
    sizeof(myArray[0]) is the size of a double (8 bytes).
    If you know the size you malloc'd then just use this instead of the sizeof(myArray) function.
    Array size (for use in bounds checking for example) is a compile-time thing in C89 (though CVI will hack in run-time bounds checking for you in a debug compile).  So even if you cast a malloc'd buffer pointer to an array type, the compiler's out of the picture at run time when the buffer gets established to a (potentially) run-time determined size, so it can't help you.  More modern languages (e.g. Java, C#) all get around this problem.  C99 allows variable length arrays to be declared but I'm not sure NI implemented this in their C99 upgrades.

  • How do i convert a double array (with spaces and tabs) to a string?

    Hi
    In our files, we have a mixture of spaces and tabs as a delimeter. How do I convert a double array into a string?
    Thank you.

    Not sure about the last part of your question.
    The Search and Replace pattern can be better than the simple Search and Replace string when you have to do complex searchs, such as detecting multiple spaces.
    Have a look at the attachment.
    CC
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    ReplaceSpaces.vi ‏27 KB

  • Copy NIVector to double array

    Hi,
    is there an easy way to copy data from an CNIReal64Vector to a double array?
    I tried to use the STL copy algorithm, but the tricky thing is that I have to copy the last element myself. Ugly...
    The method gets a pointer to an array : double* autoSpectrum1[]
    CNiReal64Vector niAutoSpectrum;
    MathError errorNI = CNiMath::AutoPowerSpectrum(timeDataVector, niAutoSpectrum, df, dt);
    size = niAutoSpectrum.GetSize();
    *autoSpectrum1 = new double[size];
    std::copy(&niAutoSpectrum[0], &niAutoSpectrum[size-1], &(*autoSpectrum1)[0]);
    (*autoSpectrum1)[size-1] = niAutoSpectrum[size-1];
    Any idea?
    Thanks
     Mario

    Hi Mario,
    Here your "double* autoSpectrum1[]" is a table of pointer.
    When you have, you can do is to do a "For Loop" and copy the element of the table pointed from your "autoSpectrum1" table and save it in a 2D table...
    I think that is the best way to do that...
    Regards...
    Matthieu

  • Hashtable and double array

    Hi,
    i need to store a series of double arrays in a hashtable.
    now while extracting them i get ClassCastException
    can anyone tell me how to extract a double array from a hashtable. if its not possible then can i use any other data structure
    thanx

    Cast it correctly?double[] darray = (double[])yourHashtable.get(yourKey);And if that doesn't work, then post the code where you put the "double array" into the Hashtable.

  • 2D double array shared variable in real-time application

    Hi,
    I am using Labview 8 and I created a real-time application using shared variables. Is it possible to create a 2D array of double (I don't find how to do itdirectly). Probably I can define my own control and load this control as the custom data type of my variable. But is it recommended to do that?
    Thank you
    Alexandre Boyer

    Another way to do this is to specify your shared variable to be a custom control and create a control that simply has a 2-D array in it.  I've attached a zipped LabVIEW 8.2 project that shows both methods.  Enjoy!
    Becky
    Becky Linton
    Field Engineer - Michigan
    National Instruments
    Attachments:
    2DArraySharedVariable.zip ‏110 KB

  • Casting arrays from double to float

    Hi, wonder if anyone can help.
    I have a method of a class that creates two double arrays (the value pointed to is a double type)
    x[][]
    y[][]
    they are essentially co-ordinates. The first dimension of the array holds the polygon number, the second the point on that polygon for the x and y respectivly.
    This method is called from (and therefore the arrays returned to) a class in an applet i am designing.
    I now have to get these co-ords into a general path for display. A general path only takes float values. I have tried all the normal casting tricks to try to convert these doubles into floats and nothing is working. Do you have to do anything special because they are in arrays.
    Any help would be appriciated.

    There is nothing special about array except that you cannot cast them.
    Instead you need to create a new set of arrays and copy/cast each value individually.

  • How to create an array of doubles??

    hi
    i want to be able to enter several numbers as string which are then converted into doubles. these will have to be stored into a doubles array. how can i do this?????
    below is somethin that i have done but i dont think its right! can some1 lend me a hand
    import java.awt.Container;
    import javax.swing.*;
    public class MaximumTest extends JApplet
    //public static void main(String args[]){
    private double[] NUM = new double[5];
    public void init()
    String s1 = JOptionPane.showInputDialog("Enter first number");
    double number1 = Double.parseDouble(s1);
    String s2 = JOptionPane.showInputDialog("Enter second number");
    double number2 = Double.parseDouble(s2);
    String s3 = JOptionPane.showInputDialog("Enter third number");
    double number3 = Double.parseDouble(s3);
    String s4 = JOptionPane.showInputDialog("Enter fourth number");
    double number4 = Double.parseDouble(s4);
    String s5 = JOptionPane.showInputDialog("Enter fifth number");
    double number5 = Double.parseDouble(s5);
    JTextArea outputArea = new JTextArea();
    outputArea.setText ("number1:" + number1 + "\nnumber2:" + number2  + "\nnumber3:" + number3  + "\nnumber4:" + number4  + "\nnumber5:" + number5);
    Container container = getContentPane();
    container.add(outputArea);
    }

    thanx again duffymo
    but how would i calculate the mean (average) (add all numbers and divide by how many there are )??????????
    below is the new code and it works fine.
    import java.awt.Container;
    import javax.swing.*;
    public class MaximumTest extends JApplet
       public static final int NUM_VALUES = 5;
       private double[] values = new double[NUM_VALUES];
       public void init()
          StringBuffer output = new StringBuffer();
          for (int i = 0; i < NUM_VALUES; ++i)
             String s = JOptionPane.showInputDialog("Enter number " + (i+1));
             values[i] = Double.parseDouble(s);
             output.append("number " + (i+1) + ": " + values[i] + "\n");
          JTextArea outputArea = new JTextArea();
          outputArea.setText(output.toString());
          Container container = getContentPane();
          container.add(outputArea);
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Array of doubles filled by DLL contains weird values

    Hello everyone
    I am working on a DLL invocation which needs to resize and fill an array of doubles named 'values' (2nd to last parameter). I have defined the signature as follows:
    _declspec (dllexport) uint8_t readDoubleArray(uint8_t handle, LStrHandle lPath, int64_t startTime,
    int64_t endTime, DblArrHdl *values, LongArrHdl *timebase);
    Where DblArrHdl is
    typedef struct {
    int32_t dimSize;
    double doubles[1];
    } DblArr;
    typedef DblArr **DblArrHdl;
    In the invocation I read doubles from a database, and resize the double array as follows:
    int size = doubleArray.size();
    if (NumericArrayResize(0x0A, 1, (UHandle*)values, size) != noErr) {
    setLastError(MG_ERR_LABVIEW_ERROR, "Failed to allocate memory");
    return FALSE;
     I set the size, and copy the values:
    (**values)->dimSize = size;
    for (int i = 0; i < size; i++) {
    (**values)->doubles[i] = doubleArray[i];
    When I use the DbgPrintF to validate the values it gives me a value around 120000 which is correct. However, when returned by labview the array contains strange data, like 5.38564E-315. Here is print out of the 'values' array after it has been through the DLL:
    Here is how I wired it, ignore the clustering, it occurs in the array of values which exits the DLL call.
    I have no idea how this can be. I followed the examples on the site. I also tried the normal DSSetHandleSize, but it didn't change anything. Any idea what I did wrong?
    Thanks in advance,
    Vincent
    Message Edited by DaVince on 10-22-2008 10:10 AM
    Solved!
    Go to Solution.
    Attachments:
    doubleArrayWeird.png ‏7 KB
    wireUpDoubles.png ‏18 KB

    You're right, this not directly described...  
    First you should read how LabVIEW stores data in memory,
    then read about structure packing pragma,
    and finally take a look to C/C++ preprocessor reference,
    then you will get feeling how to solve this problem...
    Otherwise own DLLs used in LabVIEW code pretty rarely, and Double precision also not very often...
    The same trouble you may get with clusters, but here behaviour described:
    "...The memory layout of a cluster depends on the platform you are running. LabVIEW may add padding between cluster elements so that those elements are aligned to certain address boundaries. Address boundaries relate to the concept of natural alignment. A piece of data is aligned on its natural boundary if the address at which it begins is a multiple of the size of the data. For example, a 4-byte integer is aligned naturally if it begins at an address which is a multiple of four. Most compilers have an upper limit on this boundary at which the restriction is relaxed. For instance, an 8-byte integer may be aligned on a 4-byte boundary. For the platforms on which LabVIEW runs, the alignment constraints are as follows:
    (Windows) Data is aligned only to 1-byte boundaries.
    (Mac OS and Linux) Data is aligned naturally up to 4-byte boundaries.
    (VxWorks PowerPC) Data is aligned naturally up to 8-byte boundaries.
    On all platforms, clusters adopt the alignment of their most restrictively aligned element..."
    best regards and happy wiring...
    Andrey.
    Message Edited by Andrey Dmitriev on 10-23-2008 03:38 PM

Maybe you are looking for