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

Similar Messages

  • 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

  • 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.

  • 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

  • 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.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • 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.

  • Converting a Double To A String

    Is it possible to convert a double to a string. I need to retrieve a double value from an array and display it as a label in an applet.
    How do I convert the double value to a string so that I can use it in the applet as a label?
    Thanks

    try this.
    double mydbl = 0;
    String mystr = null;
    mysstr=mydbl+"".trim();
    Paulthis one is nice paul, but it is also possible to do it that way:
    double d = 0;
    String dStr = Double.toString(d);see also API for classes Boolean, Character, Integer, Byte, Float, Short
    all primitives can easyli be turned int for in which you can print them out.

  • Convert blob to array

    Hello everybody.
    I saw an article that describes how to bind array parameter.
    The main idea is to send Varchar and convert it to array in a function.
    This is the article:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:146012348066
    The function is:
    <code>
    create or replace function in_list( p_string in varchar2 )
    return myTableType
    as
    l_data myTableType := myTableType();
    l_string long default p_string || ',';
    l_n number;
    begin
    loop
    exit when l_string is null;
    l_data.extend;
    l_n := instr( l_string, ',' );
    l_data( l_data.count ) :=
    substr( l_string, 1, l_n-1 );
    l_string := substr( l_string, l_n+1 );
    end loop;
    return l_data;
    end;
    <code>
    I want to send blob (binary) and convert it to array like the function do.
    I want to send blob because the function above uses varchar that restrict to 4k and I want to send more than 4k chars.
    How to do that?
    Edited by: DevMTs on Mar 1, 2010 10:13 AM

    The example I gave works - it just produces an extra null line so you need to modify it as follows:
    create or replace function in_list( p_string in clob) return myTableType
    as
    l_data myTableType := myTableType();
    l_n number := -1;
    old_l_n number := 0;
    begin
    loop
    l_n := instr( p_string || ',' , ',', old_l_n+1);
    exit when l_n = 0;
    l_data.extend;
    l_data( l_data.count ) := substr( p_string|| ',', old_l_n+1, l_n-old_l_n-1);
    old_l_n := l_n;
    end loop;
    return l_data;
    end;I do not understand why you are getting an error
    what have you defined the myTableType as?
    what version of Oracle are you on?
    Below I what I did to test the above function:
    create type myTableType as table of varchar2(400);
    -- generate clob with over 4K
    var x clob;
    declare
      i number
    begin
      for i in 1..12 loop
         :x := :x || lpad('Loop - ' || i, 400) || ',';
      end loop
      :x := 'The End';
    end;
    -- test function
    select * from table(in_list(:x));

  • How to convert a 2D array of pixels in to a grayscale planar image

    Im having following problems, I hope someone may help me.
    1.     I want to convert a 2D array of pixels (Grayscale values) into a Grayscale PlannerImage. I tried the following code I found on net.
    The steps to do this are:
    -Construct a DataBuffer from your data array.
    -Construct a SampleModel describing the data layout.
    -Construct a Raster from the DataBuffer and SampleModel. You can use methods from the RasterFactory class to do this.
    -Construct a ColorModel which describes your data. The factory method PlanarImage.createColorModel(sampleModel) will take care of this for some common cases.
    -Construct a TiledImage with the SampleModel and ColorModel.
    -Populate the TiledImage with your data by using the TiledImage.setData() method to copy your raster into the TiledImage.
    Only the last step involves any actual processing. The rest is just object creation.
    public static RenderedImage createRenderedImage(float[][] theData, int width, int height, int numBands) {
    int len = width * height * numBands;
    Point origin = new Point(0,0);
    // create a float sample model
    SampleModel sampleModel =
    RasterFactory.createBandedSampleModel(DataBuffer.TYPE_FLOAT,width,height,numBands);
    // create a compatible ColorModel
    ColorModel colourModel = PlanarImage.createColorModel(sampleModel);
    // create a TiledImage using the float SampleModel
    TiledImage tiledImage = new TiledImage(origin,sampleModel,width,height);
    // create a DataBuffer from the float[][] array
    DataBufferFloat dataBuffer = new DataBufferFloat(theData, len);
    // create a Raster
    Raster raster = RasterFactory.createWritableRaster(sampleModel,dataBuffer,origin);
    // set the TiledImage data to that of the Raster
    tiledImage.setData(raster);
    RenderedImageAdapter img = new RenderedImageAdapter((RenderedImage)tiledImage);
    return img;
    I passed it 2D array of pixels with 3 bands, and it gave an exception >>Array index out of bounds at this line >>tiledImage.setData(raster). Then I tried it with a 1D array of length height*width with a single band. So Now it gives me a monochromatic RenderedImage. How can I make it a grayscale PlanarImage.

    jyang, thank you very much for your response. I believe I found a different solution all together, by converting each 16-bit intensity value into an 8-bit intensity value via an intensity ratio (ie: divide each intensity by the maximum and multiply by 256). The attachment shows the new program.
    Attachments:
    mod_image.vi ‏2004 KB

  • 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?

  • 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

  • Convertion of byte array in UTF-8 to GSM character set.

    I want to convert byte array in UTF-8 to GSM character set. Please advice How can I do that?

    String s = new String(byteArrayInUTF8,"utf-8");This will convert your byte array to a Java UNICODE UTF-16 encoded String on the assumption that the byte array represents characters encoded as utf-8.
    I don't understand what GSM characters are so someone else will have to help you with the second part.

  • How can i convert a double to float

    double gallons;
    double startOdometer;
    double endOdometer;
    double mpg;
    double miles;
    endOdometer = Double.parseDouble (inputs);
    miles = endOdometer - startOdometer;                                                                 
    mpg = (miles/gallons) ;
    gallons = miles/mpg;
    mpg = Float.parseFloat(double);

    You would use a cast.
    double d = 1.4;
    float f = (float) d;But why do you want to convert a double into a float and then store it back into a double?????

  • How to convert arraylist into array

    how to convert arraylist into array?

    If you are using generics, I would use this version of toArray:
    List < X > list = ...
    X[] array = list.toArray(new X[list.size()]);If you are not using generics, that same thing looks like:
    List  list = ...
    X[] array = (X[]) list.toArray(new X[list.size()]);

  • How to convert an int array to string array?

    Hi,
    Can anyone please help me with this question?
    int number={4,6,45,3,2,77};
    I like to convert this into a list and sort
    List mylist = Arrays.asList(number);
    Collections.sort(mylist);
    But first I need to convert the int array to String array.
    Please advise. Thanks.

    If you want to convert your int array to a String array, you have no choice but doing a conversion element by element in a for loop.
    However, if the sort method doesn't behave as desired, you can use the one with 2 parameters, the second parameter being a comparator class.
    Check the javadoc for more information : http://java.sun.com/j2se/1.3/docs/api/java/util/Collections.html
    /Stephane

Maybe you are looking for

  • Hello, we have a Problem with Adobe Photoshop CS6 and VM Ware.

    Hello, our Problem is: A user uses VM Ware and the OS: WIN7 She made Screenshots in the VM Ware, the Screenshots she want to edit in Photoshop, but then Photoshop lag a lot. The PC has 16 GB RAM, but uses just 9 GB ( 6 GB for the VM(she needs 6 GB ,

  • Issue when opening Xcelsius-file in InfoView

    Hi all, We have a setup with following hw/sw: Srv: MS Windows 2003 SP2 4 GB RAM 40 GB HD (9 GB unused) Intel Xeon E5430 @ 2.66 GHz BO Edge XI 3.1 Integration Kit for SAP systems Microsoft Office 2003 Crystal Reports 2008 Xcelsius 2008 Live Office The

  • Slow slow photos in iOS 8.02

    I have  upgraded my iPad 4 to iOS 8.02, and now photos is extremly slow. First the iPad use time to consider if it want to open the file. then it make a temporarely photo, and at last it show me the photo. Its 40 MB photos, but i have no problem befo

  • Org unit assignment?

    Hi ...      i need some clarifications     1) can we assign contact person to org unit? i know we can assign emplyee to position...but what about contcat person...     2)if we assign a target group to Marketing plan does that come to campaign element

  • Landed Costs Question

    Hello! I need your help on Landed Cost. I have a few goods receipts that are open to perform Landed Cost.  But these goods receipts do not require landed cost. I thought it was probably coming from Item Master Set up.  Customs Group was set 'Al Targe