Jump to content

split function giving IndexOutOfBound errors


dprogrammer

Recommended Posts

I am using split function as follows. It only works if the number of elements in a string is equal to [ ] index. But if I increase the index to [4] but keep the string same ,it throws an error "java.lang.ArrayIndexOutOfBoundsException: 4 ". Below is just a sample string and in actuality a field will be replaced with the string "abc...". Since the field may contain from 1 to several elements, I am not sure how to dynamically use split function there. Thanks in advance for your valuable input.

("abc;def;ghi;jkl").split(";")[0]
+"\n\r"+("abc;def;ghi;jkl").split(";")[1]
+"\n\r"+("abc;def;ghi;jkl").split(";")[2]
+"\n\r"+("abc;def;ghi;jkl").split(";")[3]    -- untill here works fine with the given string
+"\n\r"+("abc;def;ghi;jkl").split(";")[4]   -- with addition of 4 (5th line) in index it throws error

 

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...