Java

Core Java With OCJP/SCJP: java.lang.package Part-14 ||String class



java
Basic Java Tutorial for beginners
Basic Java Programming for beginners
Core Java By Durga Sir
Core Java
Core Java Video Tutorials
Core Java Tutorial for beginners with examples
Core Java Tutorial
Core Java DURGASOFT
Durgasoft Core Java
Durgasoft Java
durga software solutions core java videos
durga software solutions java
How to learn java
How to learn java programming language for beginners
learn java
learn java programming for beginners
programming in java
understanding java
java…

Similar Posts

23 thoughts on “Core Java With OCJP/SCJP: java.lang.package Part-14 ||String class
  1. public static void main(String[] args) {

    String s = new String("rishu");

    String s1 = new String("rishu");

    String s2=s1.concat("nahar");

    String s3=s2.intern();

    System.out.println(s2==s3);

    String s4="rishabhnahar";

    System.out.println(s3==s4);

    System.out.println(System.identityHashCode(s));

    System.out.println(System.identityHashCode(s1));

    System.out.println(System.identityHashCode(s2));

    System.out.println(System.identityHashCode(s3));

    System.out.println(System.identityHashCode(s4));

    output:
    true

    true

    366712642

    1829164700

    2018699554

    2018699554

    2018699554

    CAN ANYONE TELL WHY THIS OUTPUT?

  2. class StringDemo
    {
    public static void main(String args[])
    {
    String s1=new String("Shubham");
    String s2=s1.concat("Pandey");
    String s3=s2.intern();
    System.out.println(s2==s3);
    String s4="ShubhamPandey";
    System.out.println(s3==s4);
    };

    };

    I am getting 'true' in both condition , why ?

  3. I'm confused!. hashcode is same for s2 and s3 objects in second example of intern() method. hence they both are equal ,jdk8. help, if any one knows exactly whats happening.

  4. This Program Output is : ture, ture in JDK8 please clarify the doubt sir. How the output is true , true;

    package org.durga;

    public class Intern_String2 {

    public static void main(String[] args) {
    // TODO Auto-generated method stub

    String s1 = new String("durga");
    String s2 = s1.concat("software");

    String s3 = s2.intern();
    System.out.println(s2==s3);

    String s4 = "durgasoftware";
    System.out.println(s3==s4);

    }

    }

Leave a Reply

Your email address will not be published. Required fields are marked *