Answers for "string and stringbuilder in java"

11

c# stringbuilder

using System;
using System.Text;

public sealed class App 
{
    static void Main() 
    {
        // Create a StringBuilder that expects to hold 50 characters.
        // Initialize the StringBuilder with "ABC".
        StringBuilder sb = new StringBuilder("ABC", 50);

        // Append three characters (D, E, and F) to the end of the StringBuilder.
        sb.Append(new char[] { 'D', 'E', 'F' });

        // Append a format string to the end of the StringBuilder.
        sb.AppendFormat("GHI{0}{1}", 'J', 'k');

        // Display the number of characters in the StringBuilder and its string.
        Console.WriteLine("{0} chars: {1}", sb.Length, sb.ToString());

        // Insert a string at the beginning of the StringBuilder.
        sb.Insert(0, "Alphabet: ");

        // Replace all lowercase k's with uppercase K's.
        sb.Replace('k', 'K');

        // Display the number of characters in the StringBuilder and its string.
        Console.WriteLine("{0} chars: {1}", sb.Length, sb.ToString());
    }
}

// This code produces the following output.
//
// 11 chars: ABCDEFGHIJk
// 21 chars: Alphabet: ABCDEFGHIJK
Posted by: Guest on March-12-2020
1

string builder in java

Java StringBuilder class is used to create
  mutable (modifiable) string. The Java
  StringBuilder class is same as StringBuffer
  class except that it is non-synchronized.
    
StringBuilder()
    creates an empty string Builder with the initial capacity of 16.
StringBuilder(String str)
    creates a string Builder with the specified string.
StringBuilder(int length)
    creates an empty string Builder with the specified capacity as length.  

StringBuilder builder = new StringBuilder("Harvard"); 
// mutable you modify object new keyword ile olusturuoyrsun StringBuilder
        builder.append(" School"); 
// append method we are calling from Builder 
//** it is not synchronized means fast
        System.out.println(builder); // Harvard School
Posted by: Guest on June-09-2021
1

what is stringbuilder used for in java

Java StringBuilder class is used to create
  mutable (modifiable) string. The Java
  StringBuilder class is same as StringBuffer
  class except that it is non-synchronized.
    
StringBuilder()
    creates an empty string Builder with the initial capacity of 16.
StringBuilder(String str)
    creates a string Builder with the specified string.
StringBuilder(int length)
    creates an empty string Builder with the specified capacity as length.
Posted by: Guest on January-14-2021
0

stringbuilder in java 8

public StringBuilder reverse()
Posted by: Guest on March-20-2021

Code answers related to "string and stringbuilder in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language