How can i cast array of string to int ?

                   while(st.hasMoreTokens()){
                              test[count] = st.nextToken();
                              count++;
                      }Since token deal with string, i have to pass them into String of array, but how can i convert all of them to int to perform arithmetic operation?

     public static void main (String[] args) throws IOException{
           DataInputStream dis = null;
             String dbRecord = null;
             int tokenCount = 0;
             int numOfQuestion = 0;
             int questionnAireNum = 0;
             int postCode = 0;
             int age = 0;
             int gender = 0;
             String [] response = new String[10];
                File f = new File("polldata.txt");
                FileInputStream fis = new FileInputStream(f); 
                BufferedInputStream bis = new BufferedInputStream(fis); 
                dis = new DataInputStream(bis);
                // read the first record of the database
                while ( (dbRecord = dis.readLine()) != null) {
                   StringTokenizer st = new StringTokenizer(dbRecord, ",");
                   tokenCount = st.countTokens();
                   numOfQuestion = tokenCount-4;
                   String rquestionNum = st.nextToken();
                   questionnAireNum = Integer.parseInt(rquestionNum);
                   String rpostCode = st.nextToken();
                   postCode = Integer.parseInt(rpostCode);
                   String rAge  = st.nextToken();
                   age = Integer.parseInt(rAge);
                   String rGender = st.nextToken();
                   gender = Integer.parseInt(rGender);
                   for(int i=0; i<numOfQuestion;i++){
                        response[i] = st.nextToken();
                   }hi how come when i cast the string as int it prompt me error as shown below ? I wonder what causes this because this is normally how i cast string to int, somehow it won work this way with token.
Exception in thread "main" java.lang.NumberFormatException: For input string: " 3"
     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
     at java.lang.Integer.parseInt(Integer.java:447)
     at java.lang.Integer.valueOf(Integer.java:553)
     at test.main(test.java:43)

Similar Messages

  • How can I return Array of String to client

    Hi all,
    I am a new learner about web services, can any one tell me how to return of get a String of array from OMElement ?
    I have two server side method want to create, first method receive an array of string and second method return an an array of String. How should I implement it.
    public org.apache.axiom.om.OMElement OneWayRequest() {
              //How Please help me
    public void LoadDummyNumberForInventory(
         org.apache.axiom.om.OMElement loadDummyNumberForInventory0) {
    //How get the String array ?
    }

    Hi all,
    I am a new learner about web services, can any one tell me how to return of get a String of array from OMElement ?
    I have two server side method want to create, first method receive an array of string and second method return an an array of String. How should I implement it.
    public org.apache.axiom.om.OMElement OneWayRequest() {
              //How Please help me
    public void LoadDummyNumberForInventory(
         org.apache.axiom.om.OMElement loadDummyNumberForInventory0) {
    //How get the String array ?
    }

  • Please tell me how can  declare an array of object.

    how to create a two dimentional array object of a class.
    let,
    class abc{
    abc(){
    is it posible--
    abc ss=new abc[10][10]
    please tell me how can declare an array object.

    then always use String and don't consider
    StringBuffer at the outset. 'best practices' need not
    be seen as premature optimization. besides, if it is
    abstracted, does not matter how it is stored
    internallyNot sure I would agree with this example - a String is immutable, if I want to change the object then using a StringBuffer makes sense (conveys the intend, yada, yada, yada).
    Although, I do agree with you that some optimizations are best practices and should be used. I also come from the old days when optimization was always on our mind. Also, I would not expect someone to do something like re-calculate a value every time it is needed instead of storing the value in a variable, just to avoid optimization.
    I just think that the example of using a 1-dimensional array when a 2-dimentional array is a better representaion of the "real world" will both obscure the intention and compicate the code.

  • How Can I replace newScale Text Strings with Custom Values?

    How Can I replace newScale Text Strings with Custom Values?
    How can I replace newScale text strings with custom values?
    All  newScale text is customizable. Follow the procedure below to change the  value of any text string that appears in RequestCenter online pages.
    Procedure
    1. Find out the String ID of the text string you would like to overwrite by turning on the String ID display:
    a) Navigate to the RequestCenter.ear/config directory.
    b) Open the newscale.properties file and add the following name-value pair at the end of the file:res.format=2
    c) Save the file.
    d) Repeat steps b and c for the RmiConfig.prop and RequestCenter.prop files.
    e) Stop and restart the RequestCenter service.
    f) Log  in to RequestCenter and browse to the page that has the text you want  to overwrite. In front of the text you will now see the String ID.
    g) Note down the String ID's you want to change.
    2. Navigate to the directory: /RequestCenter.ear/RequestCenter.war/WEB-INF/classes/com/newscale/bfw.
    3. Create the following sub-directory: res/resources
    4. Create the following empty text files in the directory you just created:
    RequestCenter_0.properties
    RequestCenter_1.properties
    RequestCenter_2.properties
    RequestCenter_3.properties
    RequestCenter_4.properties
    RequestCenter_5.properties
    RequestCenter_6.properties
    RequestCenter_7.properties
    5. Add the custom text strings to the appropriate  RequestCenter_<Number>.properties file in the following manner  (name-value pair) StringID=YourCustomTextString
    Example: The StringID for "Available Work" in ServiceManager is 699.
    If you wanted to change "Available Work" to "General Inbox", you  would add the following line to the RequestCenter_0.properties file
         699=General Inbox
    Strings are divided into the following files, based on their numeric ID:
    Strings are divided into the following files, based on their numeric ID:
    String ID  File Name
    0 to 999 -> RequestCenter_0.properties
    1000 to 1999 -> RequestCenter_1.properties
    2000 to 2999 -> RequestCenter_2.properties
    3000 to 3999 -> RequestCenter_3.properties
    4000 to 4999 -> RequestCenter_4.properties
    5000 to 5999 -> RequestCenter_5.properties
    6000 to 6999 -> RequestCenter_6.properties
    7000 to 7999 -> RequestCenter_7.properties
    6. Turn off the String ID display by removing (or commenting out) the line "res.format=2" from the newscale.properties, RequestCenter.prop and RmiConfig.prop files
    7. Restart RequestCenter.
    Your customized text should be displayed.

    I've recently come across this information and it was very helpful in changing some of the inline text.
    However, one place that seemed out of reach with this method was the three main buttons on an "Order" page.  Specifically the "Add & Review Order" button was confusing some of our users.
    Through the use of JavaScript we were able to modify the label of this button.  We placed JS in the footer.html file that changes the value of the butt

  • How can I display on a string the symbol omega (ohms)

    how can I display on a string the symbol omega (ohms)

    Hi,
    See there : http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=135&HOID=50650000000800000032410000&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0
    Hope this helps !
    Julien

  • CS3/CS4/CS5 Win/Mac: How can I convert a Windows string to mac?

    Hi
    I have a Windows coded string. I like to convert this string into a Macintosh string. This means several characters are changed, e.g. ä, ö or ü.
    Is there a method in the Indesign SDK?
    How can I convert a windows string into a macintosh string and back?
    Thanks
    Hans

    I don't think this should work that way. If this string is in resource file, use UTF-8 encoding and make PMString do its job. use kResourceUTF8Encoded in StringTable:
    resource StringTable (kSDKDefStringsResourceID + index_enUS)
            k_enUS,                                             // Locale Id
            kResourceUTF8Encoded,                         // Character encoding converter (irp) I made this WinToMac as we have a bias to generate on Win...
                  // ----- Menu strings
                    kWFPCompanyKey,                         kWFPCompanyValue,
                    kWFPAboutMenuKey,                         kWFPPluginName "[US]...",
                    kWFPPluginsMenuKey,                    kWFPPluginName "[US]",
                        kWFPDialogMenuItemKey,               "Show dialog[US]",
                    kSDKDefAboutThisPlugInMenuKey,               kSDKDefAboutThisPlugInMenuValue_enUS,
                    // ----- Command strings
                    // ----- Window strings
                    // ----- Panel/dialog strings
                        kWFPDialogTitleKey,     kWFPPluginName "[US]",
                        kWFP_Tuna_Key,     "Tuna",
                        kWFP_Salmon_Key,     "Salmon",
                        kWFP_Bonito_Key,     "Bonito",
                        kWFP_Yellowtail_Key, "Yellowtail",
                        kWFP_Currency_Key, "$",
              // ----- Misc strings
                    kWFPAboutBoxStringKey,               kWFPPluginName " [US], version " kWFPVersion " by " kWFPAuthor "\n\n" kSDKDefCopyrightStandardValue "\n\n" kSDKDefPartnersStandardValue_enUS,
    Message was edited by: Maciej Przepióra

  • How can I set Array field which reside in a Structure field?

    I use Adobe java XMP toolkit.
    There are a few methods for setting structure and array items.
    setStructField() and appendArrayItem().
    However ducu stated that member of Structure may be array or structure, moreover array items also may be arrays or structures.
    So how can I set Array field in Structure or Structure field in Array???
    Thanks
    Andrey

    OK, it worked first time (without exception) as I tried to set value of EXISTING field.
    The trick is to add array or struct BEFORE setting their values.
    This short example shows how it works:
    XMPSchemaRegistry registry = XMPMetaFactory.getSchemaRegistry();
        registry.registerNamespace(extNS, "pdfaExtension");
        registry.registerNamespace(shemaNS, "pdfaSchema");
        registry.registerNamespace(propertyNS, "pdfaProperty");
        XMPMeta m = XMPMetaFactory.create();
        m.appendArrayItem(extNS, "pdfaExtension:schemas", new PropertyOptions().setArray(true), "", new PropertyOptions().setStruct(true));
        m.setProperty(extNS, "pdfaExtension:schemas[1]/pdfaSchema:prefix", "dc");
        m.setProperty(extNS, "pdfaExtension:schemas[1]/pdfaSchema:namespaceURI", "http://purl.org/dc/elements/1.1/");
        m.setProperty(extNS, "pdfaExtension:schemas[1]/pdfaSchema:schema", "Dublin Core Schema");
        m.appendArrayItem(extNS, "pdfaExtension:schemas[1]/pdfaSchema:property", new PropertyOptions().setArrayOrdered(true), null, new PropertyOptions()
            .setStruct(true));
        m.setProperty(extNS, "pdfaExtension:schemas[1]/pdfaSchema:property[1]/pdfaProperty:name", "contributor", null);
        m.setProperty(extNS, "pdfaExtension:schemas[1]/pdfaSchema:property[1]/pdfaProperty:category", "external", null);
        m.setProperty(extNS, "pdfaExtension:schemas[1]/pdfaSchema:property[1]/pdfaProperty:description",
            "Contributors to the resource (other than the authors).", null);
        m.setProperty(extNS, "pdfaExtension:schemas[1]/pdfaSchema:property[1]/pdfaProperty:valueType", "bag ProperName", null);
        m.appendArrayItem(extNS, "pdfaExtension:schemas[1]/pdfaSchema:property", new PropertyOptions().setArrayOrdered(true), null, new PropertyOptions()
            .setStruct(true));
        m.setProperty(extNS, "pdfaExtension:schemas[1]/pdfaSchema:property[2]/pdfaProperty:name", "coverage", null);
        m.setProperty(extNS, "pdfaExtension:schemas[1]/pdfaSchema:property[2]/pdfaProperty:category", "external", null);
        m.setProperty(extNS, "pdfaExtension:schemas[1]/pdfaSchema:property[2]/pdfaProperty:description", "The extent or scope of the resource.", null);
        m.setProperty(extNS, "pdfaExtension:schemas[1]/pdfaSchema:property[2]/pdfaProperty:valueType", "Text", null);
    Above code creates following XMP:
    <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.1.1">
      <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
        <rdf:Description rdf:about=""
            xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/"
            xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#"
            xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#">
          <pdfaExtension:schemas>
            <rdf:Bag>
              <rdf:li rdf:parseType="Resource">
                <pdfaSchema:prefix>dc</pdfaSchema:prefix>
                <pdfaSchema:namespaceURI>http://purl.org/dc/elements/1.1/</pdfaSchema:namespaceURI>
                <pdfaSchema:schema>Dublin Core Schema</pdfaSchema:schema>
                <pdfaSchema:property>
                  <rdf:Seq>
                    <rdf:li rdf:parseType="Resource">
                      <pdfaProperty:name>contributor</pdfaProperty:name>
                      <pdfaProperty:category>external</pdfaProperty:category>
                      <pdfaProperty:description>Contributors to the resource (other than the authors).</pdfaProperty:description>
                      <pdfaProperty:valueType>bag ProperName</pdfaProperty:valueType>
                    </rdf:li>
                    <rdf:li rdf:parseType="Resource">
                      <pdfaProperty:name>coverage</pdfaProperty:name>
                      <pdfaProperty:category>external</pdfaProperty:category>
                      <pdfaProperty:description>The extent or scope of the resource.</pdfaProperty:description>
                      <pdfaProperty:valueType>Text</pdfaProperty:valueType>
                    </rdf:li>
                  </rdf:Seq>
                </pdfaSchema:property>
              </rdf:li>
            </rdf:Bag>
          </pdfaExtension:schemas>
        </rdf:Description>
      </rdf:RDF>
    </x:xmpmeta>

  • How can i get getwayed url string using pluggable nav in news portlet?

    hi.
    How can i get getwayed url string using pluggable nav in news portlet?
    A code just like below is what I want.
    <param value="param=http://.../portal/server.pt/gateway/PTARGS_.../http/...">
    I tryed the following, but didn't work as I wanted.
    1.<param value="<pcs:valueexpr='var'/>">
    -> transformed. but I want the prefix 'param=' in the enquoted string's too.
    2. <param value="param=<pcs:valueexpr='var'/>">
    -> not transformed.
    Any idea?
    Hiroyuki

    Hi all,
    We have HPROF functionality in our latest roadmap, so you will see that feature in our next major release called JRockit R28.
    I recommend, above from the MemLeak documentation suggested by Makiey, the following information on how to use JRockit tools.
    Performance Tuning & Profiling:
    http://download.oracle.com/docs/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/part_02.html
    Using JRockit tools:
    http://download.oracle.com/docs/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/part_03.html
    Diagnostics & Troubleshooting
    http://download.oracle.com/docs/cd/E13150_01/jrockit_jvm/jrockit/geninfo/diagnos/part_04.html
    Best Regards,
    Tuva
    JRockit PM

  • How can I cast in runtime

    Hi,
    I have read many pages of this forum, but I haven't found answer to my problem. It is very simple.
    Object o = new JDialog();
    Class cl = JDialog.class;
    JDialog jd = (JDialog)o;
    jd = cl.cast(o);The last row go to compile time error, why? How can I cast, if my class is only available by a variable?
    Thanks

    _dnoyeB wrote:
    There is no point in casting to a class if you don't plan to call a specific method on that class' interface.
    Why are you casting to a class and you don't even know what it is? I can see not knowing what you are casting from, but not knowing what you are casting too makes no sense.Yes, I want to call a method of a given class, but - in the particulat context - only what I have is an instance (object) of that class. I didn't want to write all of my use case rather the final question to have to solve. I thought the object.cast() is the solution, but it don't work. Why? That is the question I am waiting for.
    It think there is an interesting situation: if object.cast() don't operate, what is it's task? My knowledge may be not too much.

  • How to convert 1D array of string to string

    How to convert 1D array of string to string.

    Maximus00, as Pavel indicated, there is a lesser known feature of "Concatenate Strings" that does exactly what your code is doing if the input is an array of strings. In one step! See attached image.
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    ConcatenateArray ofStrings.gif ‏7 KB

  • How can I get in a String a text.... ?

    How can I get in a String a text in database,
    I tried =result.getString("fieldName") but don�t
    work.
    Tiago ticdd

    try this:
    String text = results.getString(columnIndex);
    or loop thru the ResultSetMetaData as follows:
    String text = results.getString(resultSetMetaData, columnName);
    function getColumnIndex(ResultSetMetaData rsmd, String columnName){
         int numCols = rsmd.getColumnCount();
         for (i=1; i <= numCols; i++){           
              if(rsmd.getColumnName(i).equalsIgnoreCase(columnName)){
                   return i;
         return -1;

  • How can I convert output data (string?) from GPIB-read to an 1D array?

    Hello all,
    I am reading a displayed waveform from my Tektronix Oscilloscope (TDS3032) via the GPIB Read VI. The format of the waveform data is: positive integer data-point representation with the most significant byte transferred first (2 bytes per data point).
    The output data of GPIB-Read looks like a string(?) where the integer numbers and a sign like the euro-currency sign are seperated by spaces e.g. #5200004C3 4 4 4 4 3C3C3........ (C represents the euro-currency sign).
    How can I convert this waveform data into a 1D/2D array of real double floatingpoint numbers (DBL) so I can handle the waveform data for data-analysis?
    It would be very nice if someone know the solution for this.
    t
    hanks

    Hi,
    First of all, I'm assuming you are using LabVIEW.
    The first you need to do is parse the string returned by the instrument. In this case you need to search for the known symbols in the string (like the euro sign) and chop the string to get the numeric strings. Here are some examples on parsing from www.ni.com:
    Keyword Search: parsing
    Once you parse the numeric strings you can use the "String/number conversion VIs" in the String pallette.
    Hope this helps.
    DiegoF.Message Edited by Molly K on 02-18-2005 11:01 PM

  • 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

  • How to make an array of strings?

    Hi,
    In my VI i need to send 3 or more strings from a server to a client over a TCP/IP connection. the problem is that when i press the send button i need all the strings to be sent together so i assume i need an array but unfortunately i dont know how to build the array. i have attached my example to this post.
    i appreciate the help!
    Rambaldi.
    Solved!
    Go to Solution.
    Attachments:
    Array of String.vi ‏11 KB

    TCPIP expects thay you send the packet as a single string.  you should format this into a single string that the client can understand.  Use string formater or concatinate string.
    I would sue something like string1,string2,string3 or <string1><string2><string3>.
    Other oprions are to build a string array, fletten to string on client side unflatten and the use the array.
    Either way if you plan on sending 1 packet you will need a single formatted string and the client must understand the format.
    You gan even get fancy and use a format like xml so you can genericly process the strings at the client.
    Paul Falkenstein
    Coleman Technologies Inc.
    CLA, CPI, AIA-Vision
    Labview 4.0- 2013, RT, Vision, FPGA

  • How can I convert an ASCII string of variable length to a HEX number?

    Hello,
    I read data from the serial port 5 times in a second (while loop) and the number of bytes read varies every time.
    The data comes in as ASCII string, and I can see the HEX representation if I connect a HEX string indicator, but I need to permanently convert data to a HEX number. 
    How can that be done?

    Like This.
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

Maybe you are looking for

  • Need Business case Explaination about the Field in Customer Master

    Hi all, I have a doubt in Customer master Record 1. Customer Group 2. Price Group 3. Price list 4. Customer Stat.group What I mentioned above fields i need business case explination, but all the above fileds are explaining  about the Price and Statis

  • How to disable other users from changing the status

    Hi, The status entry field can be changed irrespective of ownership in Documents. I was able to change the status on the document created by other user. Example: The status of document was In-Work. The document owner was X. But I was able to change i

  • Why can't I edit in Photoshop any more

    I reinstalled both LR4.2RC and Photoshop CS5 on a new drive. But now I can't seem to edit in Photoshop from LR. Am I doing something wrong? It worked fine before (except for getting the "Render in Lightroom" thing because of the differnece in process

  • Strange readings on alternative log in for usage m...

    Has anyone else using the alternative log in to view the broadband usage monitor when on unlimited usage noticed excessive usage displayed for the last 2 days... Every thing this month was my normal usage until 18/11/14 18/11 I am supposed to have us

  • HT204003 Can't get app to work

    When I open the app it shows 4 icons - none of which open when I touch them.  On the bottom of the screen I can touch "App Store" which takes me to another page and says "Cannot connect to iTunes Store"  I have to hit ok and then it DOES take me to i