what is the difference between a = a + b and a += b? [duplicate] - java

This question already has answers here:
Difference between a += 10 and a = a + 10 in java? [duplicate]
(5 answers)
Closed 9 years ago.
I know that both this statements evaluate to same answer but
is there any performance issue related to this statements?

The generated code will be the same for both. The only difference is to the readability of the code.

Related

What does this statement in Java mean? [duplicate]

This question already has answers here:
What is the Java ?: operator called and what does it do?
(17 answers)
Closed 4 years ago.
I am confused by this statement. Please help me explain this statement:
return third == Long.MIN_VALUE ? (int)first : (int)third;
Considering your top tags in SO is Python, let's explain this statement with Python:
return first if third == sys.maxint else third
Of course the Long.MIN_VALUE is not necessarily equal to sys.maxint in Python.

String format query [duplicate]

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

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("\\.$", "");

How do I recognize "/" in string? [duplicate]

This question already has answers here:
How do I compare strings in Java?
(23 answers)
Closed 7 years ago.
I've used
String[] red = linija.split("(?!^)");
and now in this String array I want to know if red[0] is "/". Tried (red[0] == "/") and with "//", please help.
Have you tried red[0].equals("/") ?

What is the difference between i+=d and i=i+d in Java? [duplicate]

This question already has answers here:
Closed 13 years ago.
Duplicate:
java += question
Why aren’t op-assign operators type safe in java?
When i is an integer and d is a double, i+=d works but i= i+d does not.
Why is this?
i = i + d does not work because you would be assigning a double to an int and that is not allowed.
The += operator casts the double automatically to an int, so that is why it works.
This is the link to the information on the spec:
http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5304

Categories