1. String otherString = "helen" + character;
2. otherString += character;
Answer from Android Killer on Stack OverflowGeeksforGeeks
geeksforgeeks.org โบ java โบ java-program-to-add-characters-to-a-string
Java Program to Add Characters to a String - GeeksforGeeks
July 23, 2025 - This method has two variants, and it returns a new string that is substring of a string where the substring begins with a character at the specified index and extends to the end of the string. ... Parameters: The beginning index, inclusive. Return Value: The specified substring. ... // Java Program to Add Characters to a String // Using substring() method // Main class // AddCharacterToStringAnyPosition public class GFG { // Method 1 // To add character to a string public static String addCharToStringUsingSubString(String str, char c, int pos) { return str.substring(0, pos) + c + str.substring
beginner here, how do i create a string by adding up chars?
Use StringBuilder and append one character at a time as you read them. More on reddit.com
string - How do I append characters in Java? - Stack Overflow
I'm already printing it out with ... out one character at a time as it's looping) I also want to know how do I return the value of that entire printed string, so that I can print it in the main method. ... Save this answer. ... Show activity on this post. Simplest way to append is just using ... More on stackoverflow.com
Java add chars to a string - Stack Overflow
I have two strings in a java program, which I want to mix in a certain way to form two new strings. To do this I have to pick up some constituent chars from each string and add them to form the new More on stackoverflow.com
Why does adding two char variables together give me "226"?
Chars, under the hood, are also numbers. Java (the language Processing is in) doesn't support "operator overloading", so when you try and + two chars together, it coerces them to a type that supports arithmetic. Now, you could argue that Java is wrong to do it this way- clearly they should be corced to Strings, which support + for concatenation. I don't disagree, but this gets into a whole historical thing about Java's implementation of so-called "primitive" types (like char) which sort of exist outside of the object oriented type system. TL;DR: use String not char if you want string-like behaviors, like concatenation. More on reddit.com
Videos
Blogger
javahungry.blogspot.com โบ 2020 โบ 06 โบ add-char-to-string.html
How to add a char to a String in Java | Java Hungry
public class JavaHungry { public static void main(String args[]) { StringBuilder str = new StringBuilder("JavaHungry"); /*Adding character at the end using StringBuilder append() function */ str.append('A'); System.out.println(str); } } Output: JavaHungryA c.
Reddit
reddit.com โบ r/javahelp โบ beginner here, how do i create a string by adding up chars?
beginner here, how do i create a string by adding up chars? : r/javahelp
September 10, 2022 - Use StringBuilder and append one character at a time as you read them.
TutorialsPoint
tutorialspoint.com โบ java-program-to-add-characters-to-a-string
Java Program to Add Characters to a String
May 30, 2025 - In the following Java program, ... new_st.insert(0,chartoadd); System.out.println(new_st); } } ... The append() method will add characters to the end of a string....
Tutorialspoint
tutorialspoint.com โบ java โบ lang โบ stringbuilder_append_char.htm
Java.lang.StringBuilder.append() Method
The java.lang.StringBuilder.append(char c) method appends the string representation of the char argument to this sequence.The argument is appended to the contents of this sequence.
GeeksforGeeks
geeksforgeeks.org โบ java โบ stringbuilder-append-method-in-java-with-examples
StringBuilder append() Method in Java - GeeksforGeeks
July 11, 2025 - This version appends a subsequence of characters from a CharSequence to the StringBuilder by using specified start and end indices.
Codecademy
codecademy.com โบ docs โบ java โบ stringbuilder โบ .append()
Java | StringBuilder | .append() | Codecademy
August 22, 2022 - ** For char[] arguments, .append() can have two additional optional int arguments: ... In this case, .append() will append the subsequence defined by the start point and length specified by start and len. The following example creates a StringBuilder with a specified String and then uses the .append() method to change it:
BeginnersBook
beginnersbook.com โบ 2014 โบ 08 โบ java-stringbuilder-append-char-c-method
Java โ StringBuilder.append(char c) Method
October 6, 2022 - public class JavaExample { public static void main(String[] args) { StringBuilder sb = new StringBuilder("BeginnersBook"); System.out.println("Old Sequence :"+sb); CharSequence cs = "google.com"; // appending chars of given char sequence from 6 to 10th sb.append(cs, 6, 10); System.out.println("New Sequence: " + sb); } }
Top answer 1 of 4
2
Simplest way to append is just using + as in s = s + c. This isn't the best way to do it performance wise since a new String is created every time (due to Strings being immutable). Instead you may use a StringBuilder e.g.
//Create outside of loop
StringBuilder sb = new StringBuilder();
//Append in loop
sb.append(c);
//Print when done
System.out.println(sb);
//Return the String to the caller
return sb.toString();
2 of 4
0
change s = ("" + c); to s+=("" + c); but i suggest you use StringBuilder
CodeGym
codegym.cc โบ java blog โบ strings in java โบ append() method in java: stringbuilder and stringbuffer
Append() Method in Java: StringBuilder and StringBuffer
September 28, 2023 - StringBuilder append(CharSequence cs, int start, int end) works almost as append(char[] cstr, int set, int length) we discussed above. However, this method specifies the first element of the subsequence and the last. It is important to remember that start is included in the subsequence, but end is not (that is, the last element in the subsequence is the element that comes before end). Why is that? It's just the way it is in Java.
CodeSpeedy
codespeedy.com โบ home โบ how to add a char to a string in java
How to add a char to a string in Java
April 24, 2020 - import java.util.*; public class Codespeedy { public static void main(String[] args) { char ch='A'; //declare a char StringBuffer str= new StringBuffer("system"); // declare a StringBuffer str.append(ch); // add char at the end of stringbuffer System.out.println(str); // print the result str.insert(0,'R'); // add char R at the beginning System.out.println(str); // print the result str.insert(1,'-'); // add char - at position 1 System.out.println(str); // print the result } }
Oracle
docs.oracle.com โบ javase โบ 8 โบ docs โบ api โบ java โบ lang โบ StringBuilder.html
StringBuilder (Java Platform SE 8 )
April 21, 2026 - The append method always adds these characters at the end of the builder; the insert method adds the characters at a specified point. For example, if z refers to a string builder object whose current contents are "start", then the method call z.append("le") would cause the string builder to ...
Java2Blog
java2blog.com โบ home โบ core java โบ string โบ add character to string in java
Add character to String in java - Java2Blog
January 13, 2021 - You can add character at start of String using + operator. Learn about how to compare characters in java using different methods ...
TutorialsPoint
tutorialspoint.com โบ append-a-single-character-to-a-string-or-char-array-in-java
Append a single character to a string or char array in java?
The append() method in the StringBuffer class adds the specified String to the contents of the current String buffer. Using this method you can append a single character to a string or char array in java. Example
W3Schools
w3schools.com โบ java โบ java_strings_concat.asp
Java Strings Concatenation
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods
GeeksforGeeks
geeksforgeeks.org โบ java โบ stringbuffer-append-method-in-java-with-examples
StringBuffer append() Method in Java with Examples - GeeksforGeeks
July 11, 2025 - The Characters of the char array ... of this sequence increases by the value of ilength. Syntax : public StringBuffer append(char[] cstr, int iset, int ilength) Parameter : This method accepts three ......
Top answer 1 of 5
15
StringBuilder builder = new StringBuilder();
builder
.append(this.toka.charAt(0))
.append(this.toka.charAt(1))
.append(this.toka.charAt(2))
.append(' ')
.append(this.eka.charAt(0))
.append(this.eka.charAt(1))
.append(this.eka.charAt(2));
System.out.println (builder.toString());
2 of 5
7
Just use always use substring() instead of charAt()
In this particular case, the values are mutable, consequently, we can use the built in String class method substring() to solve this problem (@see the example below):
Example specific to the OP's use case:
muutettu1 += toka.substring(0,1) + toka.substring(1,2) + eka.substring(2);
muutettu2 += eka.substring(0,1) + eka.substring(1,2) + toka.substring(2);
Concept Example, (i.e Example showing the generalized approach to take when attempting to solve a problem using this concept)
muutettu1 += toka.substring(x,x+1) + toka.substring(y,y+1) + eka.substring(z);
muutettu2 += eka.substring(x,x+1) + eka.substring(y,y+1) + toka.substring(z);
"...Where x,y,z are the variables holding the positions from where to extract."