+ 2
Why this errorException in thread "main" java.util.NoSuchElementException
9 odpowiedzi
+ 5
Ibney Ali
Thanks for the cooperation.
Please don't forget to remove it here too.
+ 4
You must enter all the required numbers line by line before running the application
For your example:
5.5
10.8
(two doubles)
+ 2
class Program
{
public static void main(String[] args) {
String a1= new String("Literal");
String a2 = "Literal";
System.out.println(a1.hashCode());
System.out.println(a2.hashCode());
}
}
Why same of both hashCode is same where both object creation is diffrent in string?
+ 1
all inputs give first.. before running...
+ 1
thanks guys
+ 1
Ibney Ali
The statement String str = new String("Literal"); creates a string object which gets stored on the heap like any other object. The string literal "test" that is passed as an argument is stored in the string constant pool.
String#intern() checks if a string constant is already available in the string pool. If there is one already it returns it, else it creates a new one and stores it in the pool.
+ 1
Pawan sir
I think this is not correct answer or may be i did not understand.
+ 1
Ibney Ali
When you use String str = new String("test"); it will creates two objects and one reference variable. In such case, JVM will create a new string object in normal(non pool) heap memory and the literal "test" will be placed in the string constant pool.
Firstly JVM will not find any string object with the value "Welcome" in string constant pool, so it will create a new object. After that it will find the string with the value "Welcome" in the pool, it will not create new object but will return the reference to the same instance.
0
you are getting the error because you are taking input two times for the variable "lu" so instead create a new variable say "li" and then replace it with the second "lu" input statement and then run