View the step-by-step solution to:


Implement a class like String class and call it MyString ( Define the following methods with your

own implementation in your class (i.e. MyString). 

public MyString(char[] chars)

Allocates a new MyString instance so that it represents the sequence of characters currently contained in the character array argument. The contents of the character array are copied; subsequent modification of the character array does not affect the newly created MyString instance. Parameters: value - The initial value of the MyString instance 

public void printMyString()

Prints this MyString instance.

public int length()

Returns the length of this MyString instance. The length is equal to the number of characters in this MyString instance. Returns: the length of the sequence of characters represented by this MyString object.

public char charAt(int index)

Returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.Parameters: index - the index of the char value. Returns: the char value at the specified index of this MyString instance. The first char value is at index 0

public MyString substring(int beginIndex , int endIndex)

Returns a MyString instance that is a substring of this MyString instance. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus, the length of the substring is endIndex-beginIndex. Examples: substring(4, 8) of "hamburger" returns "urge" substring(1, 5) of "smiles"returns "mile" Parameters: beginIndex - the beginning index, inclusive. endIndex - the ending index, exclusive. Returns: the specified substring.

public MyString toLowerCase()

Converts all of the characters in this MyString instance to lower case. Returns: the MyString instance, converted to lowercase.

public boolean equals(MyString s)

Compares this MyString instance to the specified MyString instance. The result is true if and only if the argument is not null and is a MyString object that represents the same sequence of characters as this MyString object. Overrides: equals in class Object.Parameters: s - The object to compare this MyString instance against Returns: true if the given MyString object represents a MyString equivalent to this MyString instance, false otherwise

public static MyString valueOf(int i)

Returns the MyString representation of the int argument. The representation is exactly the one returned by the Integer.toString method of one argument. Parameters: i - an int. Returns: a MyString representation of the int argument.

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Let our 24/7 Java Programming tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors