aspose file tools*
The moose likes Java in General and the fly likes Getting previous element in Enumaration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Getting previous element in Enumaration" Watch "Getting previous element in Enumaration" New topic
Author

Getting previous element in Enumaration

Jayasri kurra
Greenhorn

Joined: Jan 21, 2012
Posts: 9
Hi Friends,

How to get previous element in Enumaration.
Thanks,
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
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

Joined: Sep 26, 2010
Posts: 139
You could use the ordinal method.

Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: Sep 26, 2010
Posts: 139
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

Joined: Sep 26, 2010
Posts: 139
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

Joined: May 30, 2012
Posts: 679
Ignore. Seems I was talking rubbish.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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

Joined: May 30, 2012
Posts: 679
Jeff Verdegan wrote:Not sure what ListIterator class you're talking about

Neither do I Ignore that post.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting previous element in Enumaration