Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between '.' and "." in java

Tags:

java

Is there a difference between concatenating strings with '' and ""?

For example, what is the difference between:

String s = "hello" + "/" + "world";

and

String s = "hello" + '/' + "world";
like image 384
iberck Avatar asked Jan 30 '09 20:01

iberck


People also ask

What is the difference between '/' and '%' operator?

Solution. The / operator is used for division whereas % operator is used to find the remainder.

What is the difference between & and &&?

& is a bitwise operator and compares each operand bitwise. It is a binary AND Operator and copies a bit to the result if it exists in both operands. (A & B) will give 12 which is 0000 1100. Whereas && is a logical AND operator and operates on boolean operands.

What is difference between and in Java?

Differences between | and || operators in Java| is a bitwise operator and compares each operands bitwise. It is a binary OR Operator and copies a bit to the result it exists in either operands. (A | B) will give 61 which is 0011 1101. Whereas || is a logical OR operator and operates on boolean operands.

Is there a difference between the >> and >>> operators in Java?

In simple words >>> always shifts a zero into the leftmost position whereas >> shifts based on sign of the number i.e. 1 for negative number and 0 for positive number. For example try with negative as well as positive numbers.


1 Answers

Literals enclosed in double quotes, e.g. "foo", are strings, whereas single-quoted literals, e.g. 'c', are chars. In terms of concatenation behaviour, there'll be no discernible difference.

Nevertheless, it's worth remembering that strings and chars aren't interchangeable in all scenarios, and you can't have a single-quoted string made up of multiple characters.

like image 96
Rob Avatar answered Nov 04 '22 04:11

Rob