How to Convert the Stream of strings into ArrayList Integer

I have a String st = "12 54 456 76ASD 243 646"
what I want to do is print it like this from the ArrayList<Integer>:
12
54
456
243
646
It should catch the "76ASD" exception as it contain String Character.
This is how I am doing, which it seems to work but when it reaches the 76ASD it catches the exception so it is not adding the rest to the Arraylist, therefore I could not print in sequence.
  public static void main(String[] args) {
        // TODO code application logic here
        getDatas(testString);
        for (int i = 0; i < at.size(); ++i) {
            System.out.println(at.get(i));
    private static ArrayList<Integer> getDatas(String aString) {
        StringTokenizer st = new StringTokenizer(aString);
        try {
            while (st.hasMoreTokens()) {
                String sts = "";
                sts = st.nextToken();
                at.add(Integer.parseInt(sts));
        } catch (Exception e) {
            System.out.println("Error: " + e);
        return at;
    }Please guide me where I am going
Thanks

paulcw wrote:
This is one of the few cases where I'd say catching an exception as part of the design is acceptable. When parsing, either something parses, or it doesn't. Using parseInt, we're parsing the string and using the result of the parse. By using a regular expression, we're parsing it twice, in two different ways, which may get out of sync. Not only that, if you have a more complicated case, like negative numbers and decimals, the regex gets really ugly.
I agree this is exactly the case where it is appropriate to try, catch, handle, move on. I sometimes wish there were an Integer.isValid(String) method, but even if there were, we'd call it, and if it returned true, we'd then call parseInt anyway, which would repeat the same work that isValid did. All it would buy us would be an if test instead of a try/catch.

Similar Messages

  • How to convert server specific date string into client specific date object

    Hi developers,
    I have a very complex issue to convert the server date string format "EEE MMM dd HH:mm:ss z yyyy" into java.util.Date object and find the difference of the client machine date to represent the elapsed time
    The problem is the server time zone and client time zone are not unique and when I try to covert the server date which is in string format to date format using SimpleDateFormat class , I got the server time as 3:30 hours appended to it. The server time zone is in IST and Client time zone format is GMT+5:30 , the appended time of 3:30 hours created the confusion in calculating the elapsed time between the server started time and client requested time
    I went through all the sites but none of them were useful
    If any help to solve the above issue is appriciated
    please send the response with the same subject line
    Advance Thanks

    Why don't you just subtract from the server time the 3:30 hours (consult api of java.util.date) before comparing with the client date? Hard to see where's the problem...

  • How to convert the x/y pixel into Lat/Lon?

    Does anyone know how to covert the X/Y coord into Lat?lon coord system? What is the formular?
    Thanks!!!
    Ming

    Depends on the projection your map is using.

  • How to convert the alv list data into pdf format

    Hi Expersts,
                      Is it possible to convert the alv list output data into PDF format? if yes, then please help me with this issue.
    thanks in advance,
    Regards,
    Samad

    hii samad,
    you can go through these link.i hope it ll solve your purpose
    How to convert list output to PDF
    Display ALV list output in PDF format
    regards,
    Shweta

  • How to convert the DMS Pdf file into XSTRING - Urgent Please......

    Experts,
    I want to download a pdf file stored in a DMS Server into Desktop using webdynpro for abap.
    First i want to convert the PDF file into XSTRING, so that i can use file download UI Element in Webdynpro to download the document...
    Im searching for any function modules for past two days, i cant able to find it.. I dont even have any idea to proceed.
    I tried using CV120_START_APPLICATION in webdynpro,but it results in vain...
    I object submission date is nearing, please help me brothers and sisters...
    Thanks,
    James...

    Hi James,
    please see the thread
    Very Urgent Convert DMS  document to XSTRING/ download
    which deals with exactly the same issue. Maybe we can close one thread and handle this within the second one.
    Best regards,
    Christoph

  • How to convert the compund case statement into decode statement

    (CASE
    WHEN FRCST = 0 AND SALE = 0 THEN 'No transaction '
    WHEN FRCST = 0 AND SALE <>0 THEN 'Sale ag. Nil Forecast : '||SALE||' Kgs'
    WHEN FRCST<> 0 AND SALE = 0 THEN 'No Sale ag. Forecast : '||FRCST||' Kgs'
    WHEN FRCST<>0 AND SALE<>0 AND DIFF=0 THEN 'No Variance'
    ELSE TO_CHAR(ROUND((DIFF/FRCST),2))||'%'
    END)VARIANCE
    How to convert this tatement to decode statement ?
    Yogesh

    Decode(FRCST,0,DECODE(SALE,0,'nO TRANSACTION','SALE AGAINST NIL FORECAST'),DECODE(SALE,0,'NO SALE AGAINST FORECAST',
    DECODE(|SALE-FORECAST|,0,'NO VARIANCE',TO_CHAR(ROUND((DIFF/FRCST),2))||'%')))As per me whole case can be replaced by above decode

  • How to convert the sql query result into xml ? PLease..Please..

    I have a table Submission Record which contain a field with mix with text string and xml data type.
    Table name: Submission Record
    Field name: RCA
    Jason
    Tomato
    <Record>AA</Record>
    Fish
    Brother
    <Record>BB</Record>
    <Record>CC</Record>
    Tom is a girl
    Its mixing with text and xml data.
    I wish to convert all into xml data as per request from management.
    my select statement is like below...but i think it may contain syntax error. Wish to get help from here.
    sqltestagain = "select '<DATA>' || RCA || '</DATA>' from Submission Record".
    Expect below will display
    <DATA>Jason</DATA>
    <DATA>Tomato</DATA>
    <DATA><Record>AA</Record></DATA>
    or any other solution for it ??
    I've tried FOR XML....DBMS_XML......but none of it worked.....

    also look at xmlelement
    SQL> select xmlelement("DATA", rca).getstringval() from
      2  (
      3  select 'Jason' RCA from dual union all
      4  select 'Tomato' from dual union all
      5  select '<Record>AA</Record>' from dual
      6  )
      7  /
    XMLELEMENT("DATA",RCA).GETSTRI
    <DATA>Jason</DATA>
    <DATA>Tomato</DATA>
    <DATA>&lt;Record&gt;AA&lt;/Record&gt;</DATA>
    SQL>

  • How to convert column with delimited string into rows

    I have a string value in a single column, delimited by colon. The number of items in the string is variable. I need to select the data from this column into separate rows based on the delimiter. I can write a function with a loop but if there is a way to do this in SQL it would be better.
    Table contains a column with data value:
    12:130:1400
    And I want to select data and return as:
    12
    130
    1400
    This in in Oracle 9i.
    Please don't post "look for pivot or transpose in the forum" as that is not a helpful answer (I have already done that).
    Thanks!
    Message was edited by:
    splinternet

    SQL> create table mytable (id,value)
      2  as
      3  select 1, '12:130:1400' from dual union all
      4  select 2, '483' from dual union all
      5  select 3, '1:2:3:4:5:6:77:888' from dual union all
      6  select 4, null from dual
      7  /
    Tabel is aangemaakt.
    SQL> select id
      2       , trim(':' from v) value
      3       , substr
      4         ( v
      5         , instr(v,':',1,t.column_value) + 1
      6         , instr(v,':',1,1 + t.column_value)
      7           - instr(v,':',1,t.column_value) - 1
      8         ) part
      9    from ( select id, ':' || value || ':' v from mytable ) m
    10       , table
    11         ( cast
    12           ( multiset
    13             ( select level l
    14                 from dual
    15              connect by rownum <= length(m.v) - length(replace(m.v,':')) - 1
    16             )
    17           as sys.dbms_debug_vc2coll
    18           )
    19         ) t
    20   order by m.id
    21       , t.column_value
    22  /
            ID VALUE                PART
             1 12:130:1400          12
             1 12:130:1400          130
             1 12:130:1400          1400
             2 483                  483
             3 1:2:3:4:5:6:77:888   1
             3 1:2:3:4:5:6:77:888   2
             3 1:2:3:4:5:6:77:888   3
             3 1:2:3:4:5:6:77:888   4
             3 1:2:3:4:5:6:77:888   5
             3 1:2:3:4:5:6:77:888   6
             3 1:2:3:4:5:6:77:888   77
             3 1:2:3:4:5:6:77:888   888
             4
    13 rijen zijn geselecteerd.Regards,
    Rob.

  • How to convert the flat file data into sap tables . ?

    how to upload flat file data into sap table . before upload mapping is also there in some filds . any one can give me some steps how to upload and mapping . ?

    Hi
    See the sample code
    REPORT zmmupload.
    Internal Table for Upload Data
    DATA: i_mara like MARA occurs 0 with header line
    PARAMETERS: p_file LIKE ibipparms-path.  " Filename
    At selection-screen on Value Request for file Name
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    Get the F4 Values for the File
      CALL FUNCTION 'F4_FILENAME'
        EXPORTING
          program_name  = syst-cprog
          dynpro_number = syst-dynnr
        IMPORTING
          file_name     = p_file.
    Upload the File into internal Table
      CALL FUNCTION 'UPLOAD'
        EXPORTING
          filename                = p_file
          filetype                = 'DAT'
        TABLES
          data_tab                = i_mara
        EXCEPTIONS
          conversion_error        = 1
          invalid_table_width     = 2
          invalid_type            = 3
          no_batch                = 4
          unknown_error           = 5
          gui_refuse_filetransfer = 6
          OTHERS                  = 7.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    Upload the Data from Internal Table
      MODIFY MARA from TABLE i_MARA.
    Regards
    Anji.

  • How to convert the output of smartforms into doc format

    Hi friends,
    I want the output of smartform to be saved in doc format. I don't want to view the printpreview screen and then save it. The way we save the output in pdf format I want it to be done in doc format. Please don't suggest this option
    After the print preview, Select the menu Goto->List Display.
    Now select the menu System->List->Save->Local File.
    Now you can select the radio buttion Rich Text Format.
    Now you save the document as a .doc file (say test.doc)
    Regards,
    Satabdi

    Hi friends,
    I want the output of smartform to be saved in doc format. I don't want to view the printpreview screen and then save it. The way we save the output in pdf format I want it to be done in doc format. Please don't suggest this option
    After the print preview, Select the menu Goto->List Display.
    Now select the menu System->List->Save->Local File.
    Now you can select the radio buttion Rich Text Format.
    Now you save the document as a .doc file (say test.doc)
    Regards,
    Satabdi

  • Convert an array of strings into a single string

    Hi
    I am having trouble trying to figure out how to convert an array of strings into a single string.
    I am taking serial data via serial read in a loop to improve data transfer.  This means I am taking the data in chunks and these chunks are being dumped into an array.  However I want to combine all elements in the array into a single string (should be easy but I can't seem to make it work).
    In addition to this I would also like to then split the string by the comma separator so if any advice could be given on this it would be much appreciated.
    Many Thanks
    Ashley.

    Well, you don't even need to create the intermediary string array, right? This does exactly the same as CCs attachment:
    Back to your serial code:
    Why don't you built the array at the loop boundary? Same result.
    You could even built the string directly as shown here.
    Message Edited by altenbach on 12-20-2005 09:39 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    autoindexing.png ‏5 KB
    concatenate.png ‏5 KB
    StringToU32Array.png ‏3 KB

  • How to convert the 3.x ABAP Routines into BI 7 ABAP Routines

    Hi All,
    I am trying to convert a BI 3.x data flow into BI 7 data flow suing DTP's.
    But i am stuck at Transformations. We have used several Routines in 3.X data flow and those routines are not converted automatically into the new data flow.
    Is there any other tool or program whcih will convert the ABAP routines automatically into the new ABAP format.
    my sample ABAP 3.x Code looks like this in Start routine,
    LOOP AT DATA_PACKAGE.
        IF (     DATA_PACKAGE-CPPVLC  EQ 0
             AND DATA_PACKAGE-CPPVOC  EQ 0
             AND DATA_PACKAGE-CPSTLC  EQ 0
             AND DATA_PACKAGE-CPQUAOU EQ 0
             AND DATA_PACKAGE-CPSVLC  EQ 0 ).
          DELETE DATA_PACKAGE.
          CONTINUE.
        ENDIF.
    I tried to replace DATA_PACKAGE with SOURCE_PACKAGE, but it did not work.
    any help will be appreciated.
    Cheers
    POPS

    I tried to replace DATA_PACKAGE with SOURCE_PACKAGE, but it did not work.
    When you use SOURCE_PACKAGE it will not have header line so you need to use workarea.
    Use something like
    LOOP AT SOURCE_PACKAGE into WA_SOURCE_PACKAGE.
    Define WA_SOURCE_PACKAGE of type SOURCE_PACKAGE.
    and replace further data_package in the code with WA_SOURCE_PACKAGE
    Hope this helps.
    Edited by: Praveen G on Jan 27, 2009 4:10 AM

  • How to convert the character value to currency/numeric

    Hi,
    See the sample code here
    data: v_qtr_field(7).
    data: w_low_limit like glt0-kslvt,
          w_amount like glt0-hslvt.
    w_low_limit = 02.
    w_max_period = 3.
    concatenate 'HSL' w_low_limit into v_qtr_field.
    *comment
    *I am looking for a field formation thru above code like in GLT0 table like HSL02,HSL03 *etc based on the value user entered in the selection *screen
    DO w_max_period TIMES
      VARYING w_amount FROM v_qtr_field NEXT v_qtr_field + 1.
       t_trans_values-dmbe2 = t_trans_values-dmbe2 + w_amount.
      ENDDO.
    I am facing problem in the Do loop as it wont allows multiple data types. can you suggest me how to convert the v_qtr_field whose data type is character to currency?

    Hi,
    Please check this code .
    PERFORM write_currency
                  USING buf_anla-urwrt t_dates-waers t_txw_anla-urwrt.
    *       FORM WRITE_CURRENCY                                           *
    *       convert currency amount to string                             *
    *       - use decimal point                                           *
    *       - remove separator characters                                 *
    *  -->  P_AMOUNT                                                      *
    *  -->  P_CURRENCY_UNIT                                               *
    *  -->  P_STRING                                                      *
    FORM WRITE_CURRENCY
         USING P_AMOUNT        TYPE P
               P_CURRENCY_UNIT LIKE TCURC-WAERS
               P_STRING        TYPE C.
      DATA: DEC2POINT(2) TYPE C VALUE ',.'.
    * convert separator to decimal point
      WRITE P_AMOUNT TO P_STRING CURRENCY P_CURRENCY_UNIT
            NO-GROUPING
            NO-SIGN
            LEFT-JUSTIFIED.
      TRANSLATE P_STRING USING DEC2POINT.
    * put minus sign before number
      IF p_amount < 0.
        SHIFT P_STRING RIGHT.
        P_STRING(1) = '-'.
      ENDIF.
    ENDFORM.
    <i>Hope This Info Helps YOU.</i>
    Regards,
    Lakshmi

  • How to convert Oracle reports previewer output into delimited file.

    How to convert Oracle reports previewer output into delimited file if the report has more than 1000 pages.
    I tried with previewer option File --> Generate to file --> Delimited file, but the report engine is crashing.Not generating .TXT file.
    I observed that this option is not working for more than 400 pages.
    I am using Oracle reports 6i version.
    Plz suggest me to generate .TXT file from Report previewer.

    You can specify a delimiter (a character or string of characters) to separate the data (boilerplate or field objects) in your report output in either of the following ways:
    On the command line using the DELIMITER keyword.
    In the Delimited Output dialog box or DelimitedData Output dialog box (displayed with File > Generate to File > Delimited or File > Generate to File > DelimitedData) in Reports Builder.
    for further information goto this link
    http://download.oracle.com/docs/cd/B14099_17/bi.1012/b13895/orbr_concepts2.htm#sthref760

  • How to convert the class in the one package to same class in the other pack

    How to convert the class in the one package to same class in the other package
    example:
    BeanDTO.java
    package cho3.hello.bean;
    public class BeanDTO {
    private String name;
    private int age;
    * @return
    public int getAge() {
         return age;
    * @return
    public String getName() {
         return name;
    * @param i
    public void setAge(int i) {
         age = i;
    * @param string
    public void setName(String string) {
         name = string;
    BeanDTO.java in other package
    package ch03.hello;
    public class BeanDTO {
    private String name;
    private int age;
    * @return
    public int getAge() {
         return age;
    * @return
    public String getName() {
         return name;
    * @param i
    public void setAge(int i) {
         age = i;
    * @param string
    public void setName(String string) {
         name = string;
    My converter lass lokks like
    public class BeanUtilTest {
         public static void main(String[] args) {
              try
                   ch03.hello.BeanDTO bean=new ch03.hello.BeanDTO();
              bean.setAge(10);
              bean.setName("mahesh");
              cho3.hello.bean.BeanDTO beanDto=new cho3.hello.bean.BeanDTO();
              ClassConverter classconv=new ClassConverter();
              //classconv.
              System.out.println("hi "+beanDto.getClass().toString());
              System.out.println("hi helli "+bean.toString()+" "+bean.getAge()+" "+bean.getName()+" "+bean.getClass());
              Object b=classconv.convert(beanDto.getClass(),(Object)bean);
              System.out.println(b.toString());
              beanDto= (cho3.hello.bean.BeanDTO)b;
              System.out.println(" "+beanDto.getAge()+" "+beanDto.getName() );
              }catch(Exception e)
                   e.printStackTrace();
    But its giving class cast exception. Please help on this..

    Do you mean "two different layers" as in separate JVMs or "two different layers" as in functional areas running within the same JVM.
    In either case, if the first class is actually semantically and functionally the same as the second (and they are always intended to be the same) then import and and use the first class in place of the second. That's beyond any question of how to get the data of the first into the second if and when you need to.
    Once you make the breakthrough and use one class instead of two I'd guess that almost solves your problem. But if you want to describe your architecture a little that would help others pin down want you're trying to do.

Maybe you are looking for

  • ISSUE ON CREATE SALES ORDER USING BAPI

    Hi,    I am creating a sales order using bapi BAPI_SALESORDER_CREATEFROMDAT2.But it it fails to create a sales order abd below is my code pls check and correct me to create a sales order. LOOP AT DATA_TAB. clear: l_order_header_in,        l_salesdocu

  • How do I keep browser from re-sizing (zooming) flash video?

    Hi, Some browsers (Opera, Explorer, Firefox 3) can zoom entire pages, including text, images, and video. My flash videos have text that degrades (pixelates) badly under these circumstances. How can I embed a flash video in DW CS3 to keep the video di

  • Apple 12w charger for ipad

    It has been my experience that the 10W adapter is not always capable of charging the iPad3 under intense usage. these are situations I am referring to: 1) using maps and GPS while connected to 4G. My iPad will actually keep discharging even though mo

  • Printing Acrobat PDF in Leopard printer menu?

    Hi all, Is it at all possible to use the Acrobat printer to print out PDF´s in Leopard from the printer menu. It went out when Leopard came in and I havent seen a solution yet. Any ideas?

  • Account merge across 2 parties?

    I have an SR open but wanted to get other input. We have a situation where we have 2 valid parties, call them Org A and Org B. Org A has two accounts, Org-A-Account-1 and Org-A-Account-2. Org B also has two accounts, Org-B-Account-1 and Org-B-Account