English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I tried looking at the API but it was still confusing.

2007-01-08 14:53:32 · 1 answers · asked by Zena 2 in Computers & Internet Programming & Design

1 answers

String.charAt() takes an int as its only parameter, and returns a char. You call the charAt() method on a String to get the character at a certain position in the String. But, the first character is at position 0, the second character is at position 1, and so forth.

So, if you have:

String str = "abcdef";
System.out.print(str.charAt(1));

The program will print "1", because that's the second character in the String (remember, we're counting up from zeo).

If the position you give it is negative, or it's bigger than the number of characters in the String minus 1, charAt() throws an IndexOutOfBoundsException.

2007-01-08 18:08:45 · answer #1 · answered by watsonc64 3 · 0 0

fedest.com, questions and answers