The method you're looking for is charAt. Here's an example:

String text = "foo";
char charAtZero = text.charAt(0);
System.out.println(charAtZero); // Prints f

For more information, see the Java documentation on String.charAt. If you want another simple tutorial, this one or this one.

If you don't want the result as a char data type, but rather as a string, you would use the Character.toString method:

String text = "foo";
String letter = Character.toString(text.charAt(0));
System.out.println(letter); // Prints f

If you want more information on the Character class and the toString method, I pulled my info from the documentation on Character.toString.

Answer from Ricardo Altamirano on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › charAt
String.prototype.charAt() - JavaScript | MDN
const sentence = "The quick brown fox jumps over the lazy dog."; const index = 4; console.log(`The character at index ${index} is ${sentence.charAt(index)}`); // Expected output: "The character at index 4 is q" ... Zero-based index of the character to be returned. Converted to an integer — undefined is converted to 0. A string representing the character (exactly one UTF-16 code unit) at the specified index.
Discussions

how to get a character value at a given index number?
Do you just want the element on the index of the string · Reports the zero-based index of the first occurrence of a specified Unicode character or string within this instance. The method returns -1 if the character or string is not found in this instance · I do think Neally’s way is the ... More on community.spiceworks.com
🌐 community.spiceworks.com
4
6
June 16, 2022
In Java How Do You Assign A Char To A Particular Index In A String?
You can't manipulate a string like that. Java Strings are immutable; in order to change them, you have to create a new one; easiest way would be using substring to cut out the parts of the string you want versus the one character you don't. Furthermore, charAt just gives you the character from the string; it's not a reference to the character than can be manipulated, it's just a copy of the character value. More on reddit.com
🌐 r/learnprogramming
3
2
November 13, 2020
Getting a character in string by index - AutoIt General Help and Support - AutoIt Forums
I have a string "hello" Is there a way to reference specific characters in the string by index? In python I could just use subscripts. In java I would just use charAt. EDIT: I could use StringMid($myString, $index, 1), but that seems tedious whenever I want to get a character from a string. More on autoitscript.com
🌐 autoitscript.com
May 11, 2011
Question about getting last char at string.
Strings, like arrays and lists, are zero-indexed in java. That means the first element (i.e. the first character in the string) is at index 0, not index 1. Because of this, the last index (i.e. the last character in the string) is at an index one less than the length of the string. For example, take the string "hello": character: h e l l o index: 0 1 2 3 4 The string is five characters long, but the last character is at index 4, not 5. More on reddit.com
🌐 r/javahelp
3
1
June 14, 2017
🌐
W3Schools
w3schools.com › java › ref_string_charat.asp
Java String charAt() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... The charAt() method returns the character at the specified index in a string.
🌐
Coderanch
coderanch.com › t › 565967 › java › Finding-index-character-array
Finding the index of a character in an array (Beginning Java forum at Coderanch)
January 30, 2012 - How that goes, roughly, is you compare each element of the char[] array at a time to the desired character, y, in a loop that iterates 0 - the length of the array, and when you find a match, you return the value of the loop's index variable. (That was the kind of answer I was hoping to get to my first question.) Can you code that? Always learning Java, currently using Eclipse on Fedora. Linux user#: 501795 ... Greg Brannon wrote:Context is always helpful. There are many ways (I'm not going to count them) to do this problem, but starting with a char[] array may not be at the top of my list. Do you have to use a char[] array? Did you consider just using a String = "abcdefg......z" with its available methods?
🌐
Baeldung
baeldung.com › home › java › java string › getting a character by index from a string in java
Getting a Character by Index From a String in Java | Baeldung
November 24, 2025 - Let’s take a look at the method signature from the String class: ... The charAt() method returns the char at the index specified in the input parameter.
Find elsewhere
🌐
Quora
quora.com › How-can-I-access-the-character-of-a-string-in-Java-without-any-in-built-functions
How to access the character of a string in Java without any in-built functions - Quora
Answer (1 of 9): You can use this code if you dont want to use any inbuilt string functions. [code]public static char[] toMyArray (String s) { StringReader reader = new StringReader (s); int k = 0; int i = 0; char[] output = new char[s.length ()]; try{ while ((k = rea...
🌐
w3resource
w3resource.com › java-exercises › string › java-string-exercise-1.php
Java - Get the character at the given index within the String
May 21, 2025 - System.out.println("The character at position 0 is " + (char)index1); // Print the character at position 0 by converting ASCII value to char. System.out.println("The character at position 10 is " + (char)index2); // Print the character at position ...
🌐
IIT Kanpur
iitk.ac.in › esc101 › 05Aug › tutorial › java › data › getchar.html
Getting Characters by Index from a String or String Buffer
You can get the character at a particular index within a string, string buffer, or string builder by invoking the charAt accessor method. The index of the first character is 0; the index of the last is length()-1.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › String.html
String (Java Platform SE 8 )
October 20, 2025 - Returns the length of this string. The length is equal to the number of Unicode code units in the string. ... Returns true if, and only if, length() is 0. ... Returns the char value at the specified index. An index ranges from 0 to length() - 1.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-get-a-character-from-a-string
Java Program to Get a Character from a String - GeeksforGeeks
July 29, 2024 - Given a String str, the task is to get a specific character from that String at a specific index. ... Get the specific character using String.charAt() method. Return the specific character.
🌐
Oracle
docs.oracle.com › javase › tutorial › java › data › manipstrings.html
Manipulating Characters in a String (The Java™ Tutorials > Learning the Java Language > Numbers and Strings)
The String class has a number of methods for examining the contents of strings, finding characters or substrings within a string, changing case, and other tasks. You can get the character at a particular index within a string by invoking the charAt() accessor method.
🌐
Sololearn
sololearn.com › en › Discuss › 306167 › how-can-you-refer-to-a-char-of-a-string
How can you refer to a char of a string. | Sololearn: Learn to code for FREE!
.charAt gives you the chart at a certain position .indexOf returns the first position a particular character is found. You can look all this up. Google for java SE API. ... Use stringVar.charAt(index) to get any one character as a char. The ...
🌐
Vultr Docs
docs.vultr.com › java › standard-library › java › lang › String › charAt
Java String charAt() - Get Character At Index | Vultr Docs
November 19, 2024 - Declare a string variable with the content of your choice. Use the charAt() method to access a character at a specific index.
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java string charat method
Java String charAt Method
September 1, 2008 - The Java String charAt() method is used to retrieve the character at the specified index. The indexes refer to the character position in the sequence. The first char value represents the 0th index, and the next char value represents the 1st ...
🌐
AutoIt
autoitscript.com › autoit v3 › autoit help and support › autoit general help and support
Getting a character in string by index - AutoIt General Help and Support - AutoIt Forums
May 11, 2011 - I have a string "hello" Is there a way to reference specific characters in the string by index? In python I could just use subscripts. In java I would just use charAt. EDIT: I could use StringMid($myString, $index, 1), but that seems tedious whenever I want to get a character from a string.