Igor
0
Q:

how to append to a string in java

public class Concat {
    String cat(String a, String b) {
        a += b;
        return a;
    }
}
2
class Main
{
	public static void main(String args[])
    {
		String myString = "";
      	for (int i = 0; i < 3; i++)
        {
        	myString += "Hello There "; 
        }
      	System.out.println(myString); // Hello There Hello There Hello There 
    }
}
1
// Java program to illustrate the 
// StringBuilder append(boolean a) 
import java.lang.*; 
  
public class Geeks { 
  
    public static void main(String[] args) 
    { 
  
        StringBuilder sb1 = new 
                      StringBuilder("Welcome to Geeksforgeeks "); 
        System.out.println("Input: " + sb1); 
  
        // Appending the boolean value 
        sb1.append(true); 
        System.out.println("Output: " + sb1); 
  
        System.out.println(); 
  
        StringBuilder sb2 = new StringBuilder("We fail- "); 
        System.out.println("Input: " + sb2); 
  
        // Appending the boolean value 
        sb2.append(false); 
        System.out.println("Output: " + sb2); 
    } 
} 
0

New to Communities?

Join the community