Character at Index in Java: Explanation & Practice
Get character at a specific position
Problem summary
Print the character at index 4 of 'Programming'.
Starter code
public class Main {
public static void main(String[] args) {
String word = "Programming";
// Print character at index 4
// Print: Character: <char>
}
}Expected output and test cases
- 5th character (index 4)
Character: r
Hints
- Use .charAt(index) method
- Indexing starts at 0
- Returns a char, not String
Related Strings exercises
- Practice String Length in Java
- Practice Convert to Uppercase in Java
- Practice Extract Substring in Java
Practice all Strings exercises · Run this idea in the Java compiler