Changing an Array of Strings to an Array of Double or Int

How would I change a string of arrays to ints or doubles...here my code:
     File inputFile = new File("testing");
        FileReader in = new FileReader(inputFile);
     BufferedReader bufin = new BufferedReader(in);
     String c;
     String[] x = new String[300];
     String[] Xcoord = new String[300];
     String[] Ycoord = new String[300];
     int counter = 1;
            while ((c = bufin.readLine()) != null)
          if( counter >= 3 )
               x[counter] = c;
               String[] xySplit = x[counter].split(" ");
               System.out.println("X: "+xySplit[0]+"  Y: "+xySplit[2]);
               Xcoord[counter] = xySplit[0];
               Ycoord[counter] = xySplit[2];
           in.close();

Use a parsing method:int i = Integer.parseInt (s);
double d = Double.parseDouble (s);>> String[] x = new String[300];
You seem like you want to use a list instead.

Similar Messages

  • Change 1D array of 32 bit integer to 1D array of BV tag

    i just want to change 1D array of 32 bit data type to 1D array of BV tag to display this in Historical trend viewer
    an urgent reply wud b highly appreciable
    VINO

    What you are asking for is not really clear for me... I assume you want your array of numeric values to be replaced by a boolean array.
    Also, I was not sure about what numeric value has to correspond with TRUE or FALSE...
    Here is a possibility to do this :
    I hope this will help you...
    Message Edité par TiTou le 03-29-200609:07 AM
    When my feet touch the ground each morning the devil thinks "bloody hell... He's up again!"
    Attachments:
    QH.png ‏6 KB

  • 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');
    }

  • I need to display an array of doubles on a table and I am loosing my percision

    Hello,
    I need to display an array of doubles on a table but I am losing my decimal precision. I am converting the array to a string in order to display it on the table with a number to decimal function. This is where I lose my precision since that control converts the double into an integer and then into the string. What control do I need to use instead of that in order to preserve my decimal precision all the way to the table? I have attached my VI. Thanks in advance!
    Gregory Osenbach, CLA
    Fluke
    Attachments:
    canalyzer_prototype_1.vi ‏52 KB

    Thank you both for the quick response. Its just the info I needed!
    Gregory Osenbach, CLA
    Fluke

  • I want to cast Array to double[]

    I make an windowsForm class for draw graph.
    It has an input param
    public FormGraph(string title, string name1, Array data1)
    I need data of double[] type for draw graph. But I think users are want to input double[] or int[] ect...
    So I try to get data as Array type and cast it to double[].
    double[] series1 = (double[])data1;
    But it throw exception about fail to cast.
    How can I cast variable type of array to double[]?

    Another option is to combine Generics with this.
    You can use generics to allow the users to pass different types of data to a method, but type specific in a different way.
    public FormGraph<T>(string title, string name1, IEnumerable<T> data1)
    var series1 = data1.Select(x => Convert.ToDouble(x)).ToArray();
    Muthukrishnan Ramasamy
    net4.rmkrishnan.net
    Use only what you need, Reduce global warming

  • 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

  • 2 D array of doubles

    I was wondering how to pass a 2D array of doubles through JNI?
    I am doing this so that I can change the 2D array to a Variant that contains a 2D array of SAFEARRAYS of doubles. Then I am going to invoke a method of a 3rd party software through COM.

    It's possible, but I believe that you'll be crazy using such an array in JNI (dereferencing lots of things etc.) and the performance will be very poor.
    You can do the following thing:
    - Convert the 2D array into a 1D array in Java code. It's faster in the Java side than doing it using JNI (basically you'll need to use a lot of System.arraycopy() calls and some multiplications and additions).
    - Transfer the 1D array to the JNI code
    - Convert it back to the Variant or SAFEARRAY(double) 2D array - I believe that if you've done the things right you'll need only to do a straight memcpy in the JNI code.

  • Sorting array double or int value and keeping the associated identifier.

    Hi,
    How would I sort an array which contains a double or int value (I know how to do that) but I also want to keep the unique identifier which is associated to array element after the array has been sorted:
    example:
    identifier: 15STH7425042735
    double: 742500.000
    Thanks,
    John J. Mitchell

    Please define an it in form of entity first and then think of operating on structured data.
    a better approach here would be please create an instances of appropriate structured data arrange them in form of a list and then apply specified logic on them
    here is an example which you might think of implementing it and would more appropriate as per your stated requirements.
    public class SampleBean implements Serializable{
       private String uniqueIdentifier = new String();
       private double appValue = 0.0;
       public void setUniqueIdentifier(String uniqueIdentifier){
           this.uniqueIdentifier = uniqueIdentifier;
       public String getUniqueIdentifier(){
          return this.uniqueIdentifier;
       public void setAppValue(double appValue){
              this.appValue = appValue;
       public double getAppValue(){
            return this.appValue;
    }Sample Comparators:
    Comparator comparator4AppValue = new Comparator(){
          public int compare(Object obj1,Object obj2){
                  return Double.compare(((SampleBean)obj1).getAppValue(),((SampleBean)obj2).getAppValue());
    Comparator comparator4UniqueIdentifier = new Comparator(){
          public int compare(Object obj1,Object obj2){
                  return ((SampleBean)obj1).getUniqueIdentifier().compareTo( ((SampleBean)obj2).getUniqueIdentifier());
    };Assuming that you have acquired an Array or List 'N' Elements of SampleBean with appropriate values.
    the belows is the method of how to sort specified Array/List
    In case of array
    SampleBean sb[] = this.getSampleBeansArray();
    // in order to sort using double value inside SampleBean array.
    Arrays.sort(sb,comparator4AppValue);
    // in order to sort using unique Identifier value inside SampleBean array.
    Arrays.sort(sb,comparator4UniqueIdentifier);In case of a list
    List sb = this.getSampleBeansList();
    // in order to sort using double value inside SampleBean array.
    Collections.sort(sb,comparator4AppValue);
    // in order to sort using unique Identifier value inside SampleBean array.
    Collections.sort(sb,comparator4UniqueIdentifier);Hope this might give you some idea of how to go about.:)
    REGARDS,
    RaHuL

  • Convert byte array to table of int

    [http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print|http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print] Hello friends.
    I'm pretty new with PL/SQL.
    I have code that run well on MSSQL and I want to convert it to PL/SQL with no luck.
    The code converts byte array to table of int.
    The byte array is actually array of int that was converted to bytes in C# for sending it as parameter.
    The TSQL code is:
    CREATE FUNCTION dbo.GetTableVarchar(@Data image)
    RETURNS @DataTable TABLE (RowID int primary key IDENTITY ,
    Value Varchar(8000))
    AS
    BEGIN
    --First Test the data is of type Varchar.
    IF(dbo.ValidateExpectedType(103, @Data)<>1) RETURN
    --Loop thru the list inserting each
    -- item into the variable table.
    DECLARE @Ptr int, @Length int,
    @VarcharLength smallint, @Value Varchar(8000)
    SELECT @Length = DataLength(@Data), @Ptr = 2
    WHILE(@Ptr<@Length)
    BEGIN
    --The first 2 bytes of each item is the length of the
    --varchar, a negative number designates a null value.
    SET @VarcharLength = SUBSTRING(@Data, @ptr, 2)
    SET @Ptr = @Ptr + 2
    IF(@VarcharLength<0)
    SET @Value = NULL
    ELSE
    BEGIN
    SET @Value = SUBSTRING(@Data, @ptr, @VarcharLength)
    SET @Ptr = @Ptr + @VarcharLength
    END
    INSERT INTO @DataTable (Value) VALUES(@Value)
    END
    RETURN
    END
    It's taken from http://www.codeproject.com/KB/database/PassingArraysIntoSPs.aspx?display=Print.
    The C# code is:
    public byte[] Convert2Bytes(int[] list)
    if (list == null || list.Length == 0)
    return new byte[0];
    byte[] data = new byte[list.Length * 4];
    int k = 0;
    for (int i = 0; i < list.Length; i++)
    byte[] intBytes = BitConverter.GetBytes(list);
    for (int j = intBytes.Length - 1; j >= 0; j--)
    data[k++] = intBytes[j];
    return data;
    I tryied to convert the TSQL code to PL/SQL and thats what I've got:
    FUNCTION GetTableInt(p_Data blob)
    RETURN t_array --t_array is table of int
    AS
    l_Ptr number;
    l_Length number;
    l_ID number;
    l_data t_array;
    BEGIN
         l_Length := dbms_lob.getlength(p_Data);
    l_Ptr := 1;
         WHILE(l_Ptr<=l_Length)
         loop
              l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
              IF(l_ID<-2147483646)THEN
                   IF(l_ID=-2147483648)THEN
                        l_ID := NULL;
                   ELSE
                        l_Ptr := l_Ptr + 4;
                        l_ID := to_number( DBMS_LOB.SUBSTR(p_Data, 4,l_ptr));
                   END IF;
                   END IF;
    l_data(l_data.count) := l_ID;
              l_Ptr := l_Ptr + 4;
         END loop;
         RETURN l_data;
    END GetTableInt;
    This isn't work.
    This is the error:
    Error report:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    06502. 00000 - "PL/SQL: numeric or value error%s"
    I think the problem is in this line:
    l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
    but I don't know how to fix that.
    Thanks,
    MTs.

    I'd found the solution.
    I need to write:
    l_ID := utl_raw.cast_to_binary_integer( DBMS_LOB.SUBSTR(p_Data, 4,l_ptr));
    instead of:
    l_ID := to_number( DBMS_LOB.SUBSTR (p_Data, 4, l_ptr));
    The performance isn't good, it's take 2.8 sec to convert 5000 int, but it's works.

  • Reading arrays of double from S7 with OPC & Datasocket

    Hi friends:
    We are developing an application with a S7-315-2DP PLC and a PC with a PCI1500PFB. We use the OPC server from Applicom. We read the data very quickly with the datasocket (arrays of boolean, arrays of doubles ...and so on, and a very big amount of data over 100 ms) but when we try to write arrays datasocket faield and we have to write item on item and the speed decrease. For intance, if we try to write doubles ( 50 items) the refresh period is over 5 seconds ( some times more since we launch the data and we read the same data on the PC). Perhaps we failed configuring the OPC but there isn´t many things to configure, perhaps the problem is the board configuration .. I don´t know.
    We
    try to find some examples that write an array of doubles on one time but..
    Thank you for yours answers.
    Javi

    Hi Javi,
    I'm not aware of any known issues writing to the Applicom OPC server. In LabVIEW there isn't anything special you need to configure to be able to write arrays of doubles through DataSocket. You can test this by using the DataSocket Server Manager, make a new member that is an array of doubles, and try reading and writing to that member. You may also want to check to make sure the data member the OPC server is expecting is an arry of doubles and not an array of singles or integers.

  • Converting 1d array of double

    I have a 1-D array of double inside of a while loop.  I would like to control the execution of the while loop based on one of the numeric values in that array (like I would stop the while loop if the numeric value in the array is less than or equal to 0).  How should I go about doing this? 
    I cant link the array directly to the "less than or equal to 0" icon because it requires a single double.  Any help would be much appreciated.  Thanks. 
    Jerry

    qiora wrote:
    I cant link the array directly to the "less than or equal to 0" icon because it requires a single double. 
    Of course you can connect an array to "less than or equal to 0". The output will be a boolean array that you can feed into a "OR array elements" or "AND array elements" to get a true if either (1) at least one array element matches or (2) all elements match, respectively.
    qiora wrote:
    I would like to control the execution of the while loop based on one of the numeric values in that array (like I would stop the while loop if the numeric value in the array is less than or equal to 0). 
    If it should be based on one specific element (e.g. element(0) or element(5)), you need to get that element using "index array" and do the comparison.
    The implementation will depend on your exact requirement. Your question is quite ambiguous.
    LabVIEW Champion . Do more with less code and in less time .

  • How to write a 2-D Array of Doubles to a binary file in LabView 8.5?

    Okay, this is driving me nuts. I got a program that worked fine in LabView 8.0 but refused to write any data after my institute upgraded to LabView 8.5. The data is stored in a 2-D array of doubles and is supposed to be written to a binary file, that has been correctly opened and got a header written to it containing some meta-data of the measurement. But when the doubles from the array should be written to the file, nothing happens. All I get is an (except for the header) empty file of 786 kB. I found out that writing works if I convert the data from the array to singles right before wiring them to the "write to binary file" VI, but for several reasons I need the data as doubles. Can anyone help me? I've tried everything anyone has written here about writing to binary files and more.
    Remember, it worked perfectly fine with an older version of LabView. Any ideas?

    It is possible that you run into a known memory optimization bug.
    Try to place an "always copy" primitive as discussed here.
    Message Edited by altenbach on 11-18-2008 09:11 AM
    LabVIEW Champion . Do more with less code and in less time .

  • Converting array of Double Precision values to U16 for MODBUS

    Hello,
    I am trying to send over pressure and temperature information via the Input Register array in MODBUS TCP.  My question is, how to I properly send over an array of double precision values without loosing my data?
    For example, my array of data looks like:
    12.0001
    32.001
    0.00051234
    0.0014838
    1.02
    12.0232
    31.920
    Thanks so much.

    Thank you Ravens Fan for replying.
    I missed one extra point of data.  Below is what I'd like to send:
    12.0001
    32.001
    0.00051234
    0.0014838
    1.02
    12.0232
    31.920
    2046
    The array above is an array of double precision values.  I will convert that array to an array of single precision floating data to reduce data size.
    Since I have eight pieces of single precision floating point data now, I will need to write to 16 registers correct?  What is the best method to split up each piece of data into two consecutive registers?
    Attached is a Slave Send Data.VI that I want to send this data through.  The end goal is to have a Master PC (not using labview, but a MODBUS utility) to read my MODBUS TCP message from the "Slave Send Data.vi" 
    Thanks
    Attachments:
    Slave Send Data.vi ‏15 KB

  • Creating polygons with an array of doubles instead of ints

    Hi,
    I want to create a polygon using:
    Polygon u = new Polygon(xPoints, yPoints, numTs);
    my problem is that my x & y points are stored in double arrays not ints. Is there a way to create a polygon using double arrays instead of ints?
    cheers,
    elmicko

    or cast them as int. imaginr posX, posY, width and height are doubles.
    Rectangle rect = new Rectangle( (int)posX, (int)posY, (int)width,(int)height );or, with an array of doubles:
    Rectangle rect = new Rectangle( (int)array[0], (int)array[1], (int)array[2],(int)array[3] );

  • Creating an array of doubles which represent an asymptotic curve.

    I want to populate an array with doubles with represent a value between 0.0 and 1.0 where array[0] = 0.0 and array[10000] = 1.0.
    I don't this array to follow a linear scale i.e. array[i+1] = array[i] + 0.0001.
    I want it to follow a distribution something like this:
    http://www.fao.org/docrep/x5685e/x5685e9k.gif
    How would I go about this?
    Thanks.

    Write a function that has the shape that you want.
    Evaluate that function at 10000 values, like say 0..9999, or .0001 up to .9999 if you prefer.
    Stick those values into an array.
    Is your question that you don't know how to write down a function that has some given shape? The picture that you sent us to is rather low on details. It has a single Label Linfinity. How rapidly does this function approach this value? Do you care? The picture appears to have an infinite slope at the origin. Do you need this? Do you just want some random function that goes through 0 and 1, is strictly increasing and basically smooth and concave to the right? You say it is an asymptotic curve, presumably approaching 1 and then you nail the 10000th value in your array to be exactly 1.0, so clearly you don't appear to care that your function actually reaches its asymptotic values.
    A function that has roughly the shape you want is the square root. Yes, that function does not have a horizontal asymptote but then again neither does your array. So just use f(x) = sqrt(x)/100.0 and evaluate between 0 and 10000.
    If you need something better than that, you will need to explain in more detail what exactly constitutes better.

Maybe you are looking for

  • Failed to install drivers in Windows Vista using MDT 2012 update 1

    I am trying to deploy physical machine with Windows vista along with drivers. After completion of deployment i see deployment is successful with no error and warnings, but it still do not install driver in the machine. To test weather i have selected

  • Apex_item.date_popup giving ORA-01403: no data found

    Hi, I'm having a problem with apex_item.date_popup(). We're using apex 4.0.2. The apex_item.text and apex_item.select_list_from_query are working fine. I have a table "dba_comp_veld". Querying this table it gives: select COMP_VELD_ID, COMP_VELD_NAAM,

  • How to calculate a week & Month in given date range (not for sele-options)

    Hi ,   I have defined 2 date parameters in sel-screen (Plz remember that date variable are not a SELECT-OPTIONS).  Now i want ot display week nos & monts in output.       Ex: date1: 20080101 & date2: 20080229. then                 weeks : 1, 2, 3,---

  • CFContent + CFOutput needs to be on same line?

    Hi everyone, recently I have been devloping a simple page for my webapp the spits out some XML data. I have it working perfectly, just like I want. However, the last line: <cfcontent type="text/xml" reset="yes" /><cfoutput>#variables.xmldata#</cfoutp

  • Built in Ethernet not showing up

    I'v got a 15inch Power book running 10.4.3 In my network settings the Built in Ethernet option is not showing up. I plug in a working ethernet cable (works fine with other powerbooks) and the computer can not detect a connection. Run network setup as