Java Out of bounds exception?

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;
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

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;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I forgot to include the link to the article I found on the Sun website...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.