reset password
Author Message
OhWhen
Posts: 14
Posted 19:09 Feb 25, 2020 |

When I try and use my swapCase() method. I get a memory address instead of the new instance. 

dkwok
Posts: 24
Posted 19:11 Feb 25, 2020 |

How are you returning array of chars?

OhWhen
Posts: 14
Posted 19:14 Feb 25, 2020 |

return objectName;

kknaur
Posts: 540
Posted 19:19 Feb 25, 2020 |

Just for clarification, no method should return the inner array of characters.  If you create a new array with the new results in it then you should pass that new array to a new CS2012String object and this object is what should be returned from the method. 

char[] temp = new char[some_length]

//do some stuff to put new data into temp

return new CS2012String(temp);

Double check that you also have a working toString method so you can print out your object.

dkwok
Posts: 24
Posted 19:19 Feb 25, 2020 |

Does your toString normally work for other methods?

OhWhen
Posts: 14
Posted 22:06 Feb 25, 2020 |

Shouldn't this theoretically work?

dkwok
Posts: 24
Posted 23:29 Feb 25, 2020 |

Why do you need arraycopy?

You don't need to copy the array, you can get the array using "this.text[i]".

You are setting the letters uppercase, but you're not storing back into the array.

Try something like:

newUpperCase[i] = Character.toUpperCase(this.text[i]);

Last edited by dkwok at 23:44 Feb 25, 2020.