Is it possible to append a single character to the end of array
or string
in java. Example:
private static void /*methodName*/ () { String character = "a" String otherString = "helen"; //this is where i need help, i would like to make the otherString become // helena, is there a way to do this? }
Use the strncat() function to append the character ch at the end of str. strncat() is a predefined function used for string handling. string. h is the header file required for string functions.
One can also use String's substring method to add character to String at given position.
In Java, char and int are compatible types so just add them with + operator. char c = 'c'; int x = 10; c + x results in an integer, so you need an explicit casting to assign it to your character varaible back.
1. String otherString = "helen" + character; 2. otherString += character;
You'll want to use the static method Character.toString(char c) to convert the character into a string first. Then you can use the normal string concatenation functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With