About 726,000 results
Open links in new tab
  1. java - Comparison of String and StringBuilder manipulation in terms

    Aug 15, 2014 · The StringBuilder array is initially sized with a capacity a bit bigger than the input string in order to accommodate the original text plus likely replacements. The output text accumulates in that pre-allocated buffer and it most likely won't need any additional memory allocation during the loop.

  2. String vs StringBuilder vs StringBuffer in Java - GeeksforGeeks

    Jan 16, 2025 · In Java, String, StringBuilder, and StringBuffer are used for handling strings. The main difference is: String: Immutable, meaning its value cannot be changed once created. It is thread-safe but less memory-efficient. StringBuilder: Mutable, not thread-safe, and more memory-efficient compared to String. Best used for single-threaded operations.

  3. String vs StringBuilder Memory Usage | Software Musings

    Nov 7, 2016 · With a StringBuilder you can append to your string without having to remove the existing part. Consider this example: Replace <Large File> on lines 50 and 69 with the path to a large file and run the sample. After running this snippet, you would notice the String method consumed more memory.

  4. java - How is memory allocated for a string? - Stack Overflow

    Jul 10, 2012 · Java Strings are immutable objects. In a way each time you create a String, there will be char [] memory allocated with number of chars in String. If you do any manipulations on that String it will be brand new object and with the length of …

  5. java - How the memory allocation is done for StringBuffer ...

    Sep 27, 2017 · new StringBuilder("A ").append("B ").append("C ").append("D ") .append("E ").append("F").toString() The literal strings like "A " aren't allocated when your line of code is executed. They get pre-allocated into the string pool when your class is loaded.

  6. A Complete Guide to String, StringBuffer and StringBuilder in Java

    Feb 14, 2025 · This article highlights the differences between String, StringBuffer, and StringBuilder in Java. String is immutable and efficient in memory usage, while StringBuffer is thread-safe but slower due to synchronization.

  7. String Memory Allocation In Java: Tips for Efficiency - JA-VA Code

    Sep 25, 2023 · Unlike the + operator, which creates new intermediate string objects at each concatenation, StringBuilder efficiently builds the final string in a memory-efficient manner, reducing unnecessary string memory allocation.

  8. Exploring Java String: Immutability, String Pool, and ... - Medium

    Oct 26, 2024 · In this article, we’ll dive into the immutability of String, explore String Pool and string interning, examine what happens when you create a String using the new keyword, and discuss the...

  9. Understanding String, StringBuilder, StringBuffer, and StringJoiner in Java

    Feb 22, 2025 · Memory Allocation and Immutability. Since String objects are immutable, every modification creates a new object in memory instead of modifying the existing one. Example:

  10. Memory usage of Java Strings and string-related objects

    Memory usage of StringBuilder and StringBuffer. These classes are essentially implemented in the same way via a shared subclass and their memory usage is identical. They differ in that methods on StringBuffer are (fairly pointlessly, but for backwards compatibility) synchronized.

  11. Some results have been removed
Refresh