About 637,000 results
Open links in new tab
  1. Strings are objects in Java, so why don't we use 'new' to create

    Jan 6, 2010 · If we use new operator to create String object, then it will create new object every time. Example: String s1="Hello"; String s2="Hello"; String s3= new String("Hello"); String s4= …

  2. Concept of String Pool And String Object Creation In Java

    May 15, 2021 · A detailed explanation of how many objects are created while using “string literals” vs using the “new” keyword and JVM allocates memory when it comes to the String class.

  3. java - Where is the new Object of String created when we concat using

    Jun 1, 2018 · When you concatenate strings using the + operator in Java, a new String object is created. Here's what happens step by step: String Immutability: In Java, String is immutable, …

  4. String Literal Vs String Object in Java - GeeksforGeeks

    May 5, 2025 · In Java, we can use String Object to initialize a string. With the help of new keyword we can create string object. Declaration: String str = new String (“GeeksForGeeks”) …

  5. Java- Creating String object using new keyword - Stack Overflow

    Feb 10, 2015 · The statement String str = new String("test"); creates a string object which gets stored on the heap like any other object. The string literal "test" that is passed as an argument …

  6. Guide to Java String Pool - Baeldung

    Mar 26, 2025 · When we create a String object using the new() operator, it always creates a new object in heap memory. On the other hand, if we create an object using String literal syntax …

  7. When to Construct a new String Object in Java - algosome.com

    As with all classes, an object of the String class is created using the new keyword. Yet java also contains shorthand ways to create a String object, for instance using quotes or using the …

  8. Different Ways to Create Objects in Java - GeeksforGeeks

    Mar 28, 2025 · List of Methods to Create Objects in Java. Using new keyword; Using clone() method; Using Deserialization; Using Constructor.newInstance() from Reflection API ; Using …

  9. What happens when we create Java objects usingnew’? - Medium

    Jun 18, 2024 · Creating an object using new () in Java involves several steps and touches upon multiple aspects of Java’s memory model, including the heap, object lifecycle, garbage …

  10. java string with new operator and a literal - Stack Overflow

    May 14, 2015 · When you create a String with literal (e.g. String str = "Hello";) the Object is not created in Heap it will be available in StringPool only, however when you create a String using …

  11. Some results have been removed
Refresh