File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting previous element in Enumaration

 
Jayasri kurra
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

How to get previous element in Enumaration.
Thanks,
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. If you need access to the previous element then you need to declare a variable and point this to the current value before you call the next() method.
 
John Vorwald
Ranch Hand
Posts: 139
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use the ordinal method.

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuart A. Burkett wrote:You can't.

John Vorwald wrote:You could use the ordinal method.


That depends on whether the OP is talking about an Enumeration or an Enum (enum). Given that he said "Enumeration" and is asking about the "previous element," my money is on Enumeration.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayasri kurra wrote:How to get previous element in Enumaration.


Why do you want to? And why are you using Enumeration in the first place? If you tell us WhatNotHow(←click), (that is, what are you trying to accomplish--going backwards with an Enumeration is just how you're trying to do it) someone can probably advise a better approach to attain your actual goal.
 
John Vorwald
Ranch Hand
Posts: 139
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's see

Enumeration: a predefined interface that tests for more elements and accesses the next element.

And the question is can Enumeration have previousElement();

Is it satisfactory to extend Enumeration? i.e.



Maybe something like


produces output
 
John Vorwald
Ranch Hand
Posts: 139
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Stuart A. Burkett wrote:You can't.

John Vorwald wrote:You could use the ordinal method.


That depends on whether the OP is talking about an Enumeration or an Enum (enum). Given that he said "Enumeration" and is asking about the "previous element," my money is on Enumeration.


Appears I need to read the question more carefully.... in order to avoid the dreaded "mouth in gear before brain is engaged" syndrome
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ignore. Seems I was talking rubbish.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuart A. Burkett wrote:ListIterator class doesn't have hasPrevious or previous methods.


Not sure what ListIterator class you're talking about, but the java.util.ListIterator interface has

hasPrevious() and previous().
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:Not sure what ListIterator class you're talking about

Neither do I Ignore that post.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now we just need to hear back from the OP as to what he's actually trying to accomplish and why getting the previous element in an Enumeration is a solution to that problem.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic