Java Out of bounds exception?

Posted on 2004-11-22
Last Modified: 2012-05-05
Help.  no matter what I do.  I'm trying to move the firstname.lastname@xxx.ccc.nnn
actually the "firstname.lastname" eventually to a field called str_akouser.
public static void InsertLetter_A_Cand_Email_t(String emailAddress,String strBdId,String strSsn)
      {    String a = null;
            a = emailAddress;
            int la_return = 0;      
            Statement stmt = null;
            Connection con = null;
            ResultSet rs = null;
            String sysDate = null;
            String str_akouser = null;
          String[] sa_email = split(emailAddress, "@");
      //I get the out of bounds exception here      
            str_akouser = sa_email[0];

private static String[] split(String theStr, String delim) {
            StringTokenizer st = new StringTokenizer(theStr, delim);
            int count = st.countTokens();
            int index = 0;
            String[] arr = new String[count];
            if (count > 0) {
                  while (st.hasMoreTokens()) {
                        arr[index] = st.nextToken();
            return arr;
Question by:coolgem
    LVL 3

    Assisted Solution

    Make sure to check that emailAddress is not null.  Also, you may want to know whether it had any "@" in it in the first place, or more than one.  Check the .length of sa_email after it comes back from your split() function.


    Accepted Solution

    I checked the Sun website and it said that you should avoid using the StringTokenizer class because it's use has been replaced by newer and better classes... they recommended the following method to achieve the same result you are after... try this code instead of what you have for the split() method:

    private static String[] split(String theStr, String delim){
       String[] arr = null;

       if (delim != null && theStr != null) {
          // the following is built-in to the String class
          arr = theStr.split(delim);

       return arr;

    Expert Comment

    I forgot to include the link to the article I found on the Sun website...


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This article is filled with multiple code samples and explanations for mathematical calculations. They are as follows: 1. General tips 2. Quadratic formula 3. Object collision 4. Projectile path General Tips       Here are some of my tips f…
    This is an explanation of a simple data model to help parse a JSON feed
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now