[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 348
  • Last Modified:

Creating 5 digit integer value

Hi I am working in Java

I have to create min 5 digit integer value that should start with 1

for example 1 should be 00001
2 should be 00002 etc

00001
00002
...
...
99999
100000
100001
100002
...
...

and if we have a list of above values, I also need to find the earliest no from the list

Please help me with this logic

Many Thanks
0
tia_kamakshi
Asked:
tia_kamakshi
1 Solution
 
ksivananthCommented:
you can't hold integer prepadded with 0s but can be manipulated using string when you want to display or print,

for e.g.,

int i = 1 ;
System.out.println( String.format( "%05d", i ) );

would print 00001

for finding the smallest from a list, use comparator and then use Collections.sort to sort. then you can take the smallest/largest from the list!
0
 
basav_comCommented:
You can create the numbers stirngs(not integers) by prepending the required number of 'Zeros'.
0
 
tia_kamakshiAuthor Commented:
Many Thanks. It works great
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now