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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:24:14+00:00 2026-06-05T11:24:14+00:00

Good Evening, I have an ArrayList (instantiated as ld_data) and I iterate forward and

  • 0

Good Evening,

I have an ArrayList (instantiated as ld_data) and I iterate forward and back looking / displaying to the user the element data. In this process I need to know when I am at the first element and the last. Detecting when I am at the last element I do as such:

if((index + 1) <= ld_data.size())
{
    ....
}

This works because the size property also is the upper bound of the ArrayList. However detecting when I am at the first element is not as easy for me. The best I’ve been able to figure out is this which seems rather lame….but it works.

if((index - 1) >= (ld_data.size() - ld_data.size()))
{
    ....
}

In the C# .NET world we have ArrayList.UpperBound or ArrayList.LowerBound is there something similiar in Java?

JB

EDIT: Further details. So for more information I am bound to a ListView. So when the user has scrolled to the first element of the list I want to show a msg “At start of list” and when they reach the end show “End of list”. I know there is a scrollbar that makes this obvious I’m just trying to give an example of what I’m doing. So this check occurs in the “OnScroll” event.

  • 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-05T11:24:16+00:00Added an answer on June 5, 2026 at 11:24 am

    Its always advised to use Iterators or ListIterator to iterate through a list. Using the list size as reference does not workout when you are modifying the list data (removing or inserting elements).

    Iterator – allow the caller to iterate through a list in one direction and remove elements from the underlying collection during the iteration with well-defined semantics

    You can use a ListIterator to iterate through the list. A ListIterator allows the programmer to traverse the list in either direction, modify the list during iteration, and obtain the iterator’s current position in the list. You can refer the below example.

    ArrayList<String> list = new ArrayList<String>();
        ListIterator<String> iterator = list.listIterator();
        while(iterator.hasNext()){
            System.out.println(iterator.next());
            ...
            ...
            System.out.println(iterator.previous());
            if(!iterator.hasPrevious()){
                System.out.println("at start of the list");
            }else if(!iterator.hasNext()){
                System.out.println("at end of the list");
            }
    
        }
    

    This is just an example showing the usage of a ListIterator, please analyze what your requirement is and implement as required.

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

Sidebar

Related Questions

Good evening, I have been trying to wrap my head about this, below, code
Good evening. For a project, I have to create a system. In this system,
Good evening, I am tired and have been fighting with this for hours. I
Good evening :-)! I have this code to use Drag & Drop method for
Good evening, I have a Dedicated Server in a data center and i want
good evening, i have a mysql table that contain the users data and i
Good evening. I have a problem. i am using has_secure_password and cause of this
Good evening. I am looking at developing some code that will collect EXIF data
Good evening, I would like to have a navigation bar which is centralised to
Good evening ladies and gentlemen, I have a problem with Java Swing that I

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.