String format query [duplicate] - java

This question already has answers here:
How can I pad an integer with zeros on the left?
(18 answers)
Closed 5 years ago.
What does it represents in java?
String.format("%01000d",0)
It prints 0 thousands times. But can anyone help how does it actually works. What does "%01000d" represents?

The first argument is a format string, here you can find the sintax:
https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax

Related

How to get substring from URL? [duplicate]

This question already has answers here:
How do I decompose a URL into its component parts in Java?
(5 answers)
In java, what's the best way to read a url and split it into its parts?
(5 answers)
Closed 3 years ago.
I have couple of URL's like
http://toidsu.abc.tnd:9083/login/pages/selection.xhtml#
http://toifsmdu.abc.tnd:9081/login/pages/selection.xhtml#
I want to get string up to 'http://toidsu.abc.tnd:9083' and 'http://toifsmdu.abc.tnd:9081'
How to do it?
Use this class to parse it for you: java.net.URI

Minusing 3 characters from the end of a string in Java [duplicate]

This question already has answers here:
How to remove the last character from a string?
(37 answers)
Closed 4 years ago.
I have a string oCustomerOrderNumber which I am passing a value into iCustomerOrderNumber. I would like to remove the last 3 characters from this iCustomerOrderNumber but unable to get this to work. Error I get is that it does not like the -.
Code:
oCustomerOrderNumber = iCustomerOrderNumber.trim() -
(iCustomerOrderNumber.length() -3);
Example. ICustomerOrderNumber is 1234567 I want oCustomerOrderNumber to be 1234.
For getting a portion of a string you can use substring method and
here you can define from where until where you want to fetch from any
String:
iCustomerOrderNumber.substring(0, iCustomerOrderNumber.length()-3);
oCustomerOrderNumber = iCustomerOrderNumber.substring(0, (iCustomerOrderNumber.length() -3));

Why is Long value not printed correctly in java? [duplicate]

This question already has answers here:
Why are integer literals with leading zeroes interpreted strangely?
(8 answers)
Closed 6 years ago.
i have declared Long checkRandom=0101010101l;
but when I am printing checkRandom it printed checkRandom==17043521
what was the reason its taking checkRandom=17043521 not checkRandom=0101010101
Just remove the leading 0:
Long checkRandom=101010101l

how to store "12000000000" or a 11 digit number in java [duplicate]

This question already has answers here:
Large Numbers in Java
(6 answers)
Closed 6 years ago.
given here only as a form of validating.Which data type to use to store such a big number
Probably what you're looking for is BigInteger, BigDecimal if you want decimals instead.

Removing unneeded zeroes [duplicate]

This question already has answers here:
Remove trailing zero in Java
(12 answers)
Closed 7 years ago.
How to delete zeroes in java (android) only if there is no non-zero value following them?
The value is stored in double and then later in string, so working on these variables would be best.
Example:
I have 12.50000
I want to have 12.5
Example2:
I have 65.4030
I want to have 65.403
Try this :
String s = 12.50000;
s = s.indexOf(".") < 0 ? s : s.replaceAll("0*$", "").replaceAll("\\.$", "");

Categories