This question already has answers here:
Initializing multiple variables to the same value in Java
(7 answers)
Closed 4 years ago.
Is it possible to assign to two variables in one statement?
E.g.
this.edge = this.side = null;
Adding one line will not cost you much, just use:
this.edge = null;
this.side = null;
Related
This question already has answers here:
Does concatenating strings in Java always lead to new strings being created in memory?
(3 answers)
Converting String to "Character" array in Java
(14 answers)
String to char array Java
(1 answer)
Closed 3 months ago.
a string created with String class can not be modified.
but when we use the += operator does it mean that the original string change?
exp:
String ch="hello"; ch+= "world";
another question:
why we don't use these instructions to display the string ?
for (int i=0;i<ch.length();i++) {System.out.println(ch[i]); }
i tried this
for (int i=0;i<ch.length();i++) {System.out.println(ch.charAt(i)); }
why it is not similar to
for (int i=0;i<ch.length();i++) {System.out.println(ch[i]); }
This question already has answers here:
How do I split a string in Java?
(39 answers)
Closed 3 years ago.
I am getting a result of "kjhvkjkasdfkjh#grouping#group_group.12018-08-20".
I am looking to split the string in java to only get the "2018-08-20".
Any suggestions? The part I want is always at the end.
String sample = "kjhvkjkasdfkjh#grouping#group_group.12018-08-20"
int SubstringStart = sample.length() - 10;
String outputsample = sample.substring(SubstringStart);
will break if string has length shorter than 10
This question already has answers here:
Java: Integer equals vs. ==
(7 answers)
Why do we use autoboxing and unboxing in Java?
(10 answers)
How can I properly compare two Integers in Java?
(10 answers)
Integer == int allowed in java
(6 answers)
Closed 4 years ago.
System.out.println(5 == new Integer(5)) output = true
Integer i31 = 2;
Integer i32 = new Integer(2);
System.out.println(i31 == i32); output = false
It rather seems since we are in function scope. hence different output.
Unable to grasp what can be different.
This question already has answers here:
What is the point of the diamond operator (<>) in Java?
(7 answers)
Why diamond operator is used for Type Inference in Java 7?
(6 answers)
Closed 5 years ago.
Gen<Integer> y=new Gen(2); // Line1
Integer x=y.getOb(); //Line 2
Gen<Integer> y1=new Gen<>(2); // Line3
Integer x1=y1.getOb();//Line4
class Gen<T>
{
T val;
Gen(T ob)
{
val=ob;
}
T getOb()
{
return val;
}
}
I am not able to find any difference between y and y1 objects. Please help me in understanding this.
FYI- It is getting compiled and giving right output.
This question already has answers here:
Java Strings: "String s = new String("silly");"
(23 answers)
What is the difference between "text" and new String("text")?
(13 answers)
Closed 8 years ago.
In java we can create String in the following 2 ways -
String str1 = new String("first string"); //1
String str2 = "second string"; //2
Is there any difference in performance with these 2 approaches? And in the second case is there any new String object created?
Thanks in advance.
The first approach forces the creation of a new String object. The second allows java to use the constant from the string pool, and should generally be preferred.