if a string contains: "Hello" (without the inverted comas),what's the length?
5? or is it 6 (is there a null value or something at the end)?
Printable View
if a string contains: "Hello" (without the inverted comas),what's the length?
5? or is it 6 (is there a null value or something at the end)?
Nope, 5.
thanks for your replies crptcblade. but i'm still in a rut...
i'm using the string tokenizer to split up a string of characters, using the contents of another string (ID) as the delimiter:
StringTokenizer st = new StringTokenizer(plaintext, ID, true);
therefore, if the string is "HEL®LO", and that "®" is not in the ID string, the return of each token should be:
H
E
L
®L
O
working with each token, i have to ignore characters that are not in the ID string.... thus i'm trying to get the last character in each token (delimiters being the values present in ID).... using:
n = get.length();
convget = get.charAt((n - 1));
no problems in compilation but errors pop up during runtime:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
ex out of range: 142
at java.lang.String.charAt(Compiled Code)
at Crypt.encrypt(Compiled Code)
at CryptDriver.main(Compiled Code)
arrrggghhhhhhhhhhhhhh!!!!!!!!!!!
Using the code below i can't see how you would get a StringIndexOutOf BoundsException unless the String had a length of zero(which you would then get a negative index). Since the error you are getting is a positive value you are trying access an index greater than length - 1.
Code:public class S{
public static void main(String[] args){
String s = "Hello";
int l = s.length();
char c = s.charAt((l - 1));
System.out.println(c);
}
}