Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9243653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:51:14+00:00 2026-06-18T08:51:14+00:00

I want split lines into list based on line starter ,am getting exception while

  • 0

I want split lines into list based on line starter ,am getting exception while trying that.

File Content :

H1|!!!!!!!!!!!!!!!!!
L1|DDDDDDDDDDDDD
L2|DDDDDDDDDDDDD
H2|!!!!!!!!!!!!!!!!!
L1|DDDDDDDDDDDDD
L2|DDDDDDDDDDDDD
L3|DDDDDDDDDDDDD
EOF

Output :

   Postring size :8
SSSSS:H1|!!!!!!!!!!!!!!!!!
0head:H1|!!!!!!!!!!!!!!!!!
1detail:L1|DDDDDDDDDDDDD
2detail:L2|DDDDDDDDDDDDD
3detail:H2|!!!!!!!!!!!!!!!!!
SSSSS:H2|!!!!!!!!!!!!!!!!!
3head:H2|!!!!!!!!!!!!!!!!!
4detail:L1|DDDDDDDDDDDDD
5detail:L2|DDDDDDDDDDDDD
6detail:L3|DDDDDDDDDDDDD
7detail:EOF
SSSSS:L1|DDDDDDDDDDDDD
SSSSS:L2|DDDDDDDDDDDDD
SSSSS:L3|DDDDDDDDDDDDD
SSSSS:EOF
hshshshshs:::::::

[[H2|!!!!!!!!!!!!!!!!!, L1|DDDDDDDDDDDDD, L2|DDDDDDDDDDDDD, L3|DDDDDDDDDDDDD, EOF]]

listOrder –is list of line String

 List<Order> listOrder = new ArrayList<Order>();
           Set<List<String>> hs = new HashSet<List<String>>();
           if(poString !=null && poString.size() > 0)
            {      

               headerstart:
               for(int i=0;i<poString.size();i++)
               {
                   String s = poString.get(i);
                   if(s.startsWith("H"))
                   {
                       List<String> tempS = new ArrayList<String>();
                       tempS.add(s);
                       System.out.println("head:"+s);
                       for(int j=i+1;i<poString.size();j++)
                       {
                           String t = poString.get(j);
                           System.out.println("detail:"+t);
                           if(t.startsWith("H"))
                           {
                               i = j-1;
                                               hs.add(tempS);
                               continue  headerstart;
                            }
                           else
                           {
                            tempS.add(t);
                           }
                       }
                       hs.add(tempS);
                   }
               }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:51:15+00:00Added an answer on June 18, 2026 at 8:51 am

    In your outer loop: –

    for(int i=0;i<poString.size();i++)
    

    When the value of i reaches poString.size() - 1, then in the inner loop: –

    for(int j=i+1;i<poString.size();j++)
    

    The value of j is initialized with poString.size(). Now since your condition is i < poString.size() which is still true for i = poString.size() - 1, you move inside the loop, and access the indexj at: –

    String t = poString.get(j);  
    

    which is IndexOutOfBounds. In fact, you will get this problem on the first iteration of the outer loop only. Since your inner loop is never breaking, due to that logical error in condition.

    So, basically, you need to change your inner loop to: –

    for(int j=i+1; j < poString.size();j++)
    

    Note that, I have only changed i to j in the condition part.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looping over all lines in a file, splitting each line into tokens based
I want to split a file(suppose a mp3) into four parts.I have tried this
I want to split a file containg HTTP response into two files: one containing
I am trying to make a disorganized text file into a list suitable for
I have a file that contains 600K+ lines of stuff I want to process.
I'm having trouble trying to convert a text file into a list of lists
I have this code Dim parts As New List(Of String)(Regex.Split(RichTextBox2.Text, ~\d)) That splits lines
I have code like that 010200345 i want split every first three digit please
I want to split a string in Javascript using split function into 2 parts.
I want to split a string like this: abc//def//ghi into a part before and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.