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

  • SEARCH
  • Home
  • 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 8301017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:46:47+00:00 2026-06-08T16:46:47+00:00

i have recrusive function which works fine. The problem is it gives stackoverflow error

  • 0

i have recrusive function which works fine. The problem is it gives stackoverflow error when the number of lines are huge. I want to put it in iterative, probably using a for loop. Need some help in doing it.

private TreeSet validate(int curLine, TreeSet errorSet) {
    int increment = 0;
    int nextLine = 0;

    if (curLine == lines.length || errorSet.size() != 0) {
        return errorSet;
    } else {
        String line = lines[curLine];

        //validation starts.  After validation, line is incremented as per the requirements

        increment = 1 //As per requirement. Depends on validation results of the line

        if (increment > 0) {
            try{
                Thread.currentThread().sleep(100);  
            }catch(Exception ex){
                System.out.println(ex); 
            }
            nextLine = (curLine + increment);
            validate(nextLine, errorSet);
        }
    }

    return errorSet;
} 

Poster’s description of the method:

The method does validates textlines, these lines has instructions of how much line has to be skipped, if the line is valid. So, if the line is valid that many of lines will be skipped using the increment. if the line is not valid increment will be 0.

  • 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-08T16:46:50+00:00Added an answer on June 8, 2026 at 4:46 pm

    I’m not sure why this was ever recursive in the first place. This is perfectly suited for the use of a FOR loop. use something like so:

    private TreeSet validate(int curLine, TreeSet errorSet) { 
       int increment = 0;
    
       if (errorSet.size() != 0)
          return errorSet;
    
       for (int curLine = 0; curLine < lines.Length; curLine += increment)
       {
          // put your processing logic in here
    
    
          // set the proper increment here.
       }
    }
    

    If the increment is always going to be 1, then you can just use curr++ instead of curLine += increment

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

Sidebar

Related Questions

I have the following regex pattern which works fine: #^(.+?)=(.+?)$#D However I want to
I have the following recursive function which works... up until a point. Then the
I have a recursive function which does a sort of tree process where each
i hoping to create a recursive function which i don't have an idea yet
I have mini recursive function which finds and hides all .mta files. It looks
I have a recursive function which contains some drawing code inside. I was advised
I have a Sharepoint list which I want to convert to a JSON via
I'm relatively new in the Java world and I have a problem which I
I have the following problem, the following function is called with conflict initialised to
I have a function which aims to perform a recursive calculation. If my function

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.