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 5848739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:54:06+00:00 2026-05-22T12:54:06+00:00

Good evening, I am having a weird issue with a method I am trying

  • 0

Good evening,

I am having a weird issue with a method I am trying to implement on Java.
I will try and describe it as well as possible:

Basically what it does is checks for the next states an Epsilon-Non Deterministic State Machine would reach, given a state and an array of possible transitions.
The method “loadEpsilon(List)” loads up the possible epsilon transitions for the given list of states.

      if (transitionList.isEmpty()){
          return new HashSet<State>(stateEntryList);
      }
      else{
          for (int i=0; i <= transitionList.size()-1; i++){
              for (int j=0; j <= stateEntryList.size()-1; j++){
                  for (Transition tr : this.transitions()){ 
                      if ((tr.fromState() == stateEntryList.get(j)) && (tr.label() == transitionList.get(i))){
                          if (!stateExitList.contains(tr.toState())){
                              stateExitList.add(tr.toState());
                          }
                      }
                  }
              }
              stateEntryList.clear();
              stateEntryList = loadEpsilon(stateExitList);
              stateExitList.clear();
          }
          return new HashSet<State>(stateEntryList);
              }

So, filling up the whole code with tracing “System.out.print”s right to the very end, just before the

    stateExitList.clear();

everything is OK. However, past that line, I print BOTH lists RIGHT after that sentence (StateExitList and StateEntryList) and they are both GONE.

I just can’t figure out why they are emptying themselves.

Any chance for help?

Thanks a lot in advanced.

EDIT: This here would be the code for loadEpsilon:

  public List<State> loadEpsilon(List<State> states) throws NoInitialStateException{
      State stateRead;
      if (states.isEmpty()){ 
          if (this.getInitialState() == null){
              throw new NoInitialStateException();
          }
          states.add(this.getInitialState());
          return loadEpsilon(states);
      }
      else{
          for (int i=0; i <= states.size()-1;i++){
              stateRead = states.get(i);
              for (Transition tr : this.transitions()){
                  if ((tr.fromState() == stateRead) && (tr.label().isEpsilon()) && (!states.contains(tr.toState()))){
                      states.add(tr.toState()); 
                      System.out.print(states.size());
                  }
              }
          }
      }
      return states; 
  } 

The declaration of the lists are the following:

      List<State> stateEntryList = new ArrayList<State>();
      stateEntryList = loadEpsilon(stateEntryList);       
      List<State> stateExitList = new ArrayList<State>();
      List<Label> listaLabels = new ArrayList<Label>();
      listaLabels.addAll(Arrays.asList(labels));
  • 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-05-22T12:54:06+00:00Added an answer on May 22, 2026 at 12:54 pm

    If stateEntryList is empty after you call stateExitList.clear() after you call loadEpsilon, that points toward the List that loadEpsilon returns being somehow tied to the stateExitList being passed to it. Perhaps the list that loadEpsilon is returning is using the list passed to it as a backing store or something like that? You really need to post the code to loadEpsilon.


    Edited:

    Well that explains it. your loadEpsilon is returning the List that was passed to it. It is returning the exact same object it was given. So you’re ending up with the same object being referred to by two names. But since it’s the same object underneath, when you clear it, it’s cleared.

    You’re basically doing this:

    List<String> list1 = new ArrayList<String>();
    list1.add("foo");
    list1.add("bar");
    
    List<String> sameList = list1;
    sameList.add("quux");
    
    list1.clear();
    

    Does that make it clearer why clearing one list clears them “both”? (Again, there’s only one object there that is being referred to by two reference variables).

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

Sidebar

Related Questions

No related questions found

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.