Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enumerable.Range() in Java?

 
Keith Flo
Ranch Hand
Posts: 128
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a kinda silly question ... but here goes ...

Is there an equivalent to Enumerable.Range() method in Java? The .Net framework has an method that takes int start and int count arguments and returns a sequence of intergers numbers within that range. Does a similar method exist in Java?



PS: Yes ... I know I can easily write a similar static method myself that takes the same arguments and returns an array (or preferably a List) but I was just wondering and Enumerables are used a lot in Linq and the Java libraries and the .Net framework have soooo many similarities.

 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keith:

Enumerations in Java (1.5+) are real classes, not integers.

John.
 
Keith Flo
Ranch Hand
Posts: 128
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,

I'm wondering if there is a similar method in Java ... I know the naming will be different ... I dont know why MS always changes the names of well known structures and patterns but they always do ...

 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keith:

No, there isn't. I did try looking in a number of promising classes, though (Integer, Arrays, Array).

John.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[pedantic mode]By Enumerations, I presume you mean enums?[/pedantic mode]
 
Keith Flo
Ranch Hand
Posts: 128
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John,
Thanks for your response ... I couldn't find anything similar ... just wondering if it might exist somewhere..


Campbell
... no I dont mean Enums .... rather in CSharp/.Net the IEnumerable interface and the Enumerable class define a 'sequence' ....

but you likely already know this ...

 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keith Flo wrote:Campbell
... no I dont mean Enums .... rather in CSharp/.Net the IEnumerable interface and the Enumerable class define a 'sequence' ....

but you likely already know this ...

No, I'm pretty sure Campbell was responding to John de Michele:
John de Michele wrote:Keith:

Enumerations in Java (1.5+) are real classes, not integers.

John.

Enumerations in Java are interfaces, not classes, and have been there since 1.0. As Campbell said, this was probably a reference to enums, not Enumerations.
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike:

Yes, I meant 'little e' enums. Unfortunately, the rules of English require capitalizing the first word, which makes it hard to accurately describe stuff in computer languages sometimes . And actually, the name of that interface is Enumeration.

John.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regardless of capitalization, there's a big difference between an Enumeration and an enum. Count the letters. You keep saying "Enumeration" when you must mean "enum". Please, stop. An Enumeration is a different thing entirely. Look it up. None of your statements here make any sense when you say Enumeration - but they do make sense if you say enum.

And Keith - no, sorry Java doesn't have anything like that.
 
John de Michele
Rancher
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike:

The term 'enum' is short for enumerated type or enumeration: Enumerated Type. I am aware of the difference between the Enumeration interface and an enum. Sun should have named the Enumeration interface something else (as implied by their javadoc), maybe 'Iterator'.

John.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic