I’m currently working on a project for a class to create a TextLine class that represents the a line of text that must be represented as an array of characters.
For one of the methods, I am supposed to take in a string as an argument of a parameter and then append that string to my already created char array.
I was trying to search online for how I could do this, or even an example of the String or StringBuffer class that showed the implementation, but due to my novice skills at Google, I couldn’t really find anything useful.
What I ‘m thinking is that I first have to convert the string to the array, and then somehow using one of the array methods to add each char individually to the char array.
This is what I have:
public void append(String fragment){
char[] temp = fragment.toCharArray();
}
I’m not quite sure what array method could be used, if there even is one. Could someone please help me?
Normally you would use a
StringBuilderas the internal storage for your class but i assume that you need the basic details of how to do this.The basic process is like this:
Here is the code (this assumes that the
datamember is declared like this:char[] data = new char[0]: