Question: HW4_P2 - MyString The String class is provided in the Java library. Provide your own implementation for the following methods (name the new class MyString

HW4_P2 - MyString

The String class is provided in the Java library. Provide your own implementation for the following methods (name the new class MyString):

**DO NOT USE THE STRING OBJECT AND ITS METHODS. IMPLEMENT THEM ALL AGAIN YOURSELF!

**You can use char[] and Character object.

public MyString(char[] chars);

public char charAt(int index);

public int length();

public MyString substring(int begin, int end);

public MyString toLowerCase();

public boolean equals(MyString s);

public static MyString valueOf(int i);

public char[] toChars();

------------------------------------------------------------------------------------

Use this code for the main (do not change, please):

class DriverMain{

public static void main(String[] args) {

MyString s1 = new MyString(new char[] {'A', 'B', 'C'});

System.out.println(s1.length());

System.out.println(s1.charAt(1));

MyString s2 = s1.substring(0,2);

System.out.println(s2.toLowerCase().equals(new MyString(new char[] {'a', 'b'})));

char[] chars = MyString.valueOf(345).toChars();

for (int i = 0; i < chars.length; i++) {

System.out.print(chars[i]);

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!