amit kumar goyal wrote:I was asked this question in an interview.....Probably they want some solution like how it is implemented in the String class....the also asked a question like how can we find the length of a String without using any inbuilt methods......
I think you are reading the question too strictly. I agree that they probably want some solution on how it is implemented -- which
you should have answered... that is it held internally as a char array, and that you can get a copy of that array, using the toCharArray() method. I am sure that they don't mean that you can't call that method.
Then to answer the substring question, you need to talk about loops and checking characters.etc. For your second question, it is simply the length of the array.
Henry