Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Java Out of bounds exception?

Posted on 2004-11-22
Medium Priority
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
  • 2

Assisted Solution

esorf earned 1000 total points
ID: 12644556
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

ralwan earned 1000 total points
ID: 12645688
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

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



Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

571 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