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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:41:40+00:00 2026-06-02T10:41:40+00:00

This might be a stupid question, but I’m having trouble thinking this through. I

  • 0

This might be a stupid question, but I’m having trouble thinking this through.

I wrote a method that uses a LinkedList to move through loaded MIDI instruments. I want to make a next and a previous button so that every time you click the button you traverse through the LinkedList.

If I hardcode itr.next(); or itr.previous(); multiple times I can traverse through the LinkedList

public void setInsturment(Synthesizer start,MidiChannel currentChannel[])
{
    try
    {
        start.open();

        Soundbank bank = start.getDefaultSoundbank();

        start.loadAllInstruments(bank);

        LinkedList<Instrument> currentInstrument = new LinkedList<Instrument>();

        Instrument instrs[] = start.getLoadedInstruments();

        currentInstrument.add(instrs[0]);
        currentInstrument.add(instrs[1]);
        currentInstrument.add(instrs[2]);
        currentInstrument.add(instrs[3]);
        currentInstrument.add(instrs[4]);

        ListIterator itr = currentInstrument.listIterator();
        itr.next();
        itr.next();
        itr.next();
     // nextInstrument();

        currentChannel[1].programChange(0,itr.nextIndex());

    }

    catch(MidiUnavailableException e)
    {
        System.out.print("error");
    }

}

I’m having a lot of trouble making a button that can traverse through the list. Is there an efficient way to do this? I tried something like this with no success.

public void actionPerformed(ActionEvent e)
{
    if (e.getSource() == nextButton)
    {
        sound.nextInstrument();
    }

public void nextInstrument()
{
    itr.next();
}

Thanks in advance guys!

  • 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-02T10:41:41+00:00Added an answer on June 2, 2026 at 10:41 am

    Well, hmm, a linked list is a List and its items can be accessed by index, this is not the optimal structure to access items by index but I really don’t know if you can have a cursor on that kind of collection but you can store the current index on an instance variable.

    If you really want random access, then you should consider using ArrayList instead of linked list.

    Example:

    class NextPrevList {
        private int index = 0;
        private List currentList; //initialize it with some list
    
        public Object next() {
            return list.get(++index);
        }
        public Object prev() {
            //maybe add a check for out of bounds
            if (index == 0) return null;
            return list.get(--index);
        }
    }
    

    Personally I think it would be more performant with an ArrayList rather than a LinkedList

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

Sidebar

Related Questions

This might be a very silly / stupid question, but, my defence is that
This might be a stupid question, but I notice that in a good number
I realise that this might be a stupid question, but I have not come
This might be a stupid question but i failed to do through tutorial found
This might be a stupid question, but is there a rule that states that
this might be a stupid question, but I'm using asp.net list control that creates
This might be a stupid question but if there's a better or proper way
This might be a stupid question but I just wanted to make sure... If
This might be a stupid question but I'm new at all this. I want
This might be a stupid question but I'll ask anyway, I was reading OOP

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.