Java String.charAt(int index) example

By Yashwant Chavan, Views 9, Date 17-May-2018

In this java tutorial, You will learn how to use String.charAt(int index) method. This method, Returns the char value at the specified index. An index ranges from 0 to length() - 1.

tags Java

Returns the char value at the specified index.

Syntax

public char charAt(int index)

Parameters

index - the index of the char value.

Returns

The char value at the specified index of this string. The first char value is at index 0.

Throws

IndexOutOfBoundsException - if the index argument is negative or not less than the length of this string.

Java String charAt(int index) example

  • Assign String value.
  • value.charAt(9);It will return the char value of the index 9 of string firstValue.
  • Print the value.
package com.technicalkeeda;

public class App {

    public static void main(String[] args) {

        String value = "Technicalkeeda";

        char result = value.charAt(9);

        System.out.println("Char value at index 9 :- " + result);
    }
}

output

Char value at index 9 :- k

Suggested Posts

Yashwant Chavan

Yashwant Chavan

Hi there! I am founder of technicalkeeda.com and programming enthusiast. My skills includes Java,J2EE, Spring Framework, Nodejs, PHP and lot more. If you have any idea that you would want me to develop? Lets connect: yashwantchavan@gmail.com