• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

data structure

 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to know if there is a little special data structure defined in API.
It should be something like photo watching under Windows system. Dealing with that structure is through 2 methods - next and previous, but if it is the last element and next() is invoked - the first element should be returned. And if it is the first element and previous() is invoked - the last element should be returned. So that's like circle. Is something like this defined in API?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked through the exiting Collection classes? Is there one that meets your requirements? If not, which one comes closest?
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that it should be somehing like list. Its ListIterator has good methods but when it gets the last element it doesn't jump to the first one - no circle. Do I have to implement my specific collection?
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the ListIterator's hasNext() method returns false, simply reset it to the start (or create a new one; that's faster). Likewise for hasPrevious().

Moving to Java in General.
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lukas:

This link might be useful to you.

John.
 
zahid zubair
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IF you want to go from last to first alone, then you can use this code:

 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i will always be >= 0 and < listSize, so wouldn't the % listSize be useless?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49363
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Useful hint, zahid Zubair ( ). It works much faster with List implementations which also implement the RandomAccess tagging interface.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic