You don't. This is probably some interview question to make you think outside the box, but the answer is simple - it's not possible. The obvious choice, String.length(), is not allowed. Another approach is to get the length of the backing char[], but that requires a call to toCharArray() - not allowed. Yet another approach is to get the next character until you encounter an IndexOutOfBoundsException (which you catch), but guess what - getting the character requires charAt(index) which is also not allowed.
If you use our search you'll find a few more threads with the same question, and the answer is going to be the same.
I found
one such thread, but that only disallowed using length(). You're not allowed to use
anything.