
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
StringIndexOutOfBoundsException: String index out of range:
Hi,
Please advise me below. Thank you!
I have below "out of range" problem after I run my job by using updated source
Previously I can run smoothly with below syntax
row1.BOL.substring(0,4).equals("EXDO")||row1.BOL.substring(0,4).equals("DMCQ")?"LCLshipment":"Invalid"
Can not find any clue for that.
Data sample for BOL is
BOL |
CMDUCAD0323962MB |
EGLV235800292095 |
206739726 |
206756945 |
206783071 |
206671602 |
206535382 |
EGLV149800286242 |
HLCUHAM180317960 |
EXDO6810670633 |
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@szhou1,use the below way and let me know?
StringHandling.LEN(row1.BOL)>4 &&(row1.BOL.substring(0,4).equals("EXDO")||row1.BOL.substring(0,4).equals("DMCQ"))?"LCLshipment":"Invalid"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
Would you mind posting your job setting screenshots on forum which will be helpful for us to address your issue?
Best regards
Sabrina

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@szhou1,use the below way and let me know?
StringHandling.LEN(row1.BOL)>4 &&(row1.BOL.substring(0,4).equals("EXDO")||row1.BOL.substring(0,4).equals("DMCQ"))?"LCLshipment":"Invalid"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thank you for your advise. I run smoothly with syntax - I am wondering why it works when I add "StringHandling.LEN(row1.BOL)>4"?
I have another question - I also have another syntax to filter if BOL# ends with letter such as "X,Y,Z,B". previously everything is good but for now it shows out of range error either. I tried to add "StringHandling.LEN(row1.BOL)>4" but NOT work.
Can you please advise me about this?
My current syntax is
row1.BOL.substring(row1.BOL.length()-1, row1.BOL.length()).equals("X")||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("Y")||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("Z")||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("B")?"Dynamic":"Invalid"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@szhou1,since your data length is less than 4 in row1.BOL for some of the values so that's way you were getting out of range" problem.
try the below one and let me know.
row1.BOL.length()>1 &&(row1.BOL.substring(row1.BOL.length()-1, row1.BOL.length()).equals("X")
||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("Y")
||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("Z")
||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("B"))?"Dynamic":"Invalid"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@szhou1,since your data length is less than 4 in row1.BOL for some of the values so that's way you were getting out of range" problem.
try the below one and let me know.
row1.BOL.length()>1 &&(row1.BOL.substring(row1.BOL.length()-1, row1.BOL.length()).equals("X")
||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("Y")
||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("Z")
||row1.BOL.substring(row1.BOL.length()-1,row1.BOL.length()).equals("B"))?"Dynamic":"Invalid"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
StringIndexOutOfBoundsException error is realted to Java substring and it means you are attempting to access a character which would come after the end of the string. If a String is only 4 characters long, attempting to get the substring from index 0 - 8, will throw this exception. substring(beginIndex, endInded) throws IndexOutOfBoundsException if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.
