Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java string equal vs ==

Case1)
String s1 = "Stack Overflow";
String s2 = "Stack Overflow";
s1 == s1;      // true
s1.equals(s2); // true
Reason: String literals created without null are stored in the string pool in the permgen area of the heap. So both s1 and s2 point to the same object in the pool.
Case2)
String s1 = new String("Stack Overflow");
String s2 = new String("Stack Overflow");
s1 == s2;      // false
s1.equals(s2); // true
Reason: If you create a String object using the `new` keyword a separate space is allocated to it on the heap.
Comment

string compareto vs equals java

compareTo() when you need to know the difference in length between strings 
that start with the same sequence of characters.
  
  System.out.println("sumit".compareTo("timus"));//-1
Comment

PREVIOUS NEXT
Code Example
Java :: hibernate onetone with mapsid 
Java :: search 
Java :: one line hashmap java 
Java :: fill array java 
Java :: arrondi java 
Java :: java animated gif example 
Java :: multiple spinner android 
Java :: java random number generator 
Java :: java questions 
Java :: java check array for duplicates 
Java :: lambda function java 
Java :: list of java 
Java :: java check prime number 
Java :: tostring java 
Java :: control structures in java 
Java :: android recyclerview pull to refresh 
Java :: get node inside node in of xml using java 
Java :: Java Add elements to a HashMap 
Java :: positive numbers in array 
Java :: the java_home environment variable is not defined correctly on mac 
Java :: Java Queue Linked List Implementation 
Java :: throw exception in spring boot with message and geeter se 
Java :: generics in java 
Java :: wrapper classes in java ebhor.com 
Java :: naming convention in selenium 
Java :: java can an object be used as a key 
Java :: h2 database spring boot create table application.properties 
Java :: Execute method on load alternative 
Java :: programme javascrip mineur et majaur 
Java :: XmlRootElement Object to String 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =