Author | Message |
---|---|
Sameen
Posts: 10
|
Posted 15:23 Feb 25, 2020 |
Whenever I try using the .length() of my own, the IDE just doesn't use mine and then starts using the length() method of the REAL JAVA STRING class... How can I use my method? How can I use the system.arraycopy in the constructor when I don't know the length and I can't use the JAVA length() method? Last edited by Sameen at
15:50 Feb 25, 2020.
|
kknaur
Posts: 540
|
Posted 15:58 Feb 25, 2020 |
You do know the length of the char array. |
Sameen
Posts: 10
|
Posted 16:00 Feb 25, 2020 |
But then we have to use the .length! We cannot hardcode the array!! |
kknaur
Posts: 540
|
Posted 16:04 Feb 25, 2020 |
Using .length of the array is not hardcoding. And it is how you tell how many characters are in your string inside the CS2012String class. |
Sameen
Posts: 10
|
Posted 16:07 Feb 25, 2020 |
So does the .length that we create tells us the size of the this.text only? |
kknaur
Posts: 540
|
Posted 16:09 Feb 25, 2020 |
Yes the length of the char array will be the same length as your CS2012String. This is so how the real String class is implemented. So your CS2012String length() method can be written in one line :). Last edited by kknaur at
16:10 Feb 25, 2020.
|
Sameen
Posts: 10
|
Posted 16:13 Feb 25, 2020 |
so in the length method we just write "return this.text.length;"? Sorry for asking this because that is the way I wrote it in my source code! |
kknaur
Posts: 540
|
Posted 16:17 Feb 25, 2020 |
Yes. |
Sameen
Posts: 10
|
Posted 16:19 Feb 25, 2020 |
Thank you very much :) |