I want to generate a series of numbers based on the range provided by a user. Like, if he provides 30-100, I want to generate numbers - 30,31,32,33,34,35...97,98,99,100. Is this possible through regular expressions in java?
Joined: May 24, 2008
Just wanted to add here that I do not want to use a solution like:
Java itself doesn't. You can use IntRange though, or use a simple collection like a Set (use TreeSet or LinkedHashSet to keep the range ordered) or a List implementation.
As for the regular expression, you can create one to extract the lower and upper bounds, but not to generate the numbers. You need to combine both solutions - one to extract the bounds, one to generate the numbers based on those bounds.
D Preethi wrote:Just wanted to add here that I do not want to use a solution like:I am looking for a more optimized way...
It may be worth pointing out that if you already have lowerbound and upperbound and all you want to do is print out the numbers in the range, that code is about as optimized as it gets. I suspect you mean more generic or flexible.
Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here