how to combine strings code example

Example 1: python merge strings

my_list = ['a', 'b', 'c', 'd']
my_string = ','.join(my_list)
# Output = 'a,b,c,d'

Example 2: python concatenate strings

print “{0} {1} is {2} years old.” format(fname, lname, age)

Example 3: how do you combine 2 strings

-By  using (+) operator
-By  using concatenate method (concat()).
                      String strconcat3=strconcat2.concat(strconcat);

-By StringBuffer
-String strconcat= new StringBuilder().append("matt")
                                .append("damon").toString();
                                
-By StringBuilder
- String strconcat2= new StringBuffer()
                  .append("matt").append("damon").toString();

Tags:

Misc Example