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

  1. Use .charAt(index) method
  2. Indexing starts at 0
  3. Returns a char, not String

Related Strings exercises

Practice all Strings exercises · Run this idea in the Java compiler