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
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_string_indexof.asp
Java String indexOf() Method
String myStr = "Hello planet earth, you are a great planet."; System.out.println(myStr.indexOf("planet")); ... The indexOf() method returns the position of the first occurrence of specified character(s) in a string.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ String โ€บ indexOf
String.prototype.indexOf() - JavaScript - MDN Web Docs
The method returns the index of the first occurrence of the specified substring at a position greater than or equal to position, which defaults to 0. If position is greater than the length of the calling string, the method doesn't search the calling string at all.
Discussions

java - Get string character by index - Stack Overflow
I know how to work out the index of a certain character or number in a string, but is there any predefined method I can use to give me the character at the nth position? So in the string "foo", if I More on stackoverflow.com
๐ŸŒ stackoverflow.com
string - How to get the position of a character in Python? - Stack Overflow
How can I get the position of a character inside a string in Python? ... Save this answer. ... Show activity on this post. There are two string methods for this, find() and index(). The difference between the two is what happens when the search string isn't found. More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to quickly get index of given string?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
๐ŸŒ r/javahelp
3
2
September 30, 2021
how to get what index position the last character of a string is
this could have been solved with 5 minutes of experimentation if you're going to be a programmer you have to start experimenting with code, just test and try stuff out More on reddit.com
๐ŸŒ r/learnpython
13
3
April 2, 2022
๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ python-substring-indexof
5 Ways to Find the Index of a Substring in Python | Built In
Below is a summary of what you need to remember about each Python string method. str.find(), str,index(): These return the lowest index of the substring.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ string โ€บ index
Python String index()
print(sentence.index('ing', 10)) # Substring is searched in 'gramming is ' print(sentence.index('g is', 10, -4)) # Substring is searched in 'programming' ... 15 17 Traceback (most recent call last): File "<string>", line 10, in print(quote.index('fun', 7, 18)) ValueError: substring not found
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ indexof-in-java-how-to-find-the-index-of-a-string-in-java
indexOf in Java โ€“ How to Find the Index of a String in Java
March 24, 2022 - A string is a collection of characters nested in double quotes. The indexOf method returns the index position of a specified character or substring in a string. In this article, we'll see the syntax for the different indexOf methods.
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ dotnet โ€บ api โ€บ system.string.indexof
String.IndexOf Method (System) | Microsoft Learn
Public Function IndexOf (value As Rune, startIndex As Integer, comparisonType As StringComparison) As Integer ... Reports the zero-based index of the first occurrence of the specified string in the current String object.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_string_index.asp
Python String index() Method
Remove List Duplicates Reverse ... Python Study Plan Python Interview Q&A Python Training ... The index() method finds the first occurrence of the specified value....
Find elsewhere
๐ŸŒ
Javatpoint
javatpoint.com โ€บ java-string-indexof
Java String.indexOf()
Java String indexOf() method with method signature and examples of concat, compare, touppercase, tolowercase, trim, length, equals, split, string indexof in java etc.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-string-indexof
Java String indexOf() Method - GeeksforGeeks
November 19, 2024 - In Java, the String indexOf() method returns the position of the first occurrence of the specified character or string in a specified string.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_indexof.asp
JavaScript String indexOf() Method
cssText getPropertyPriority() ... = text.indexOf("Welcome"); Try it Yourself ยป ... The indexOf() method returns the position of the first occurrence of a value in a string....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-find-index-containing-string-in-list
Python - Find Index containing String in List - GeeksforGeeks
July 23, 2025 - It involves identifying the position where a specific string appears within the list. index() method in Python is used to find the position of a specific string in a list.
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2013 โ€บ 12 โ€บ java-string-indexof-method-example
Java String indexOf() Method
July 1, 2024 - Java String indexOf() method is used to find the index of a specified character or a substring in a given String.
๐ŸŒ
IIT Kanpur
iitk.ac.in โ€บ esc101 โ€บ 05Aug โ€บ tutorial โ€บ java โ€บ data โ€บ getchar.html
Getting Characters by Index from a String or String Buffer
String anotherPalindrome = "Niagara. O roar again!"; char aChar = anotherPalindrome.charAt(9); Indices begin at 0, so the character at index 9 is 'O', as illustrated in the following figure: Use the charAt method to get a character at a particular index. The figure also shows that to compute ...
๐ŸŒ
Medium
medium.com โ€บ @muraliairody โ€บ find-and-index-of-string-6c50c819273c
Find and Index of String
October 24, 2025 - But if the substring is not found, it raises a ValueError instead of returning -1. ... text = "Hello Python" print(text.index("Python")) # 6 # print(text.index("Java")) # ValueError: substring not found ยท Featurefind()index()Return value if substring not found-1Raises ValueErrorUsageSafer if substring may not existUse when you are sure substring existsBothReturn first occurrence indexReturn first occurrence index
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ string_index.htm
Python String index() Method
The python string index() method is used to return the index of the input string where the substring is found. Basically, it helps us to find out if the specified substring is present in the input string.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-string-index-method
Python String index() Method - GeeksforGeeks
May 2, 2025 - The index() method in Python is used to find the position of a specified substring within a given string. It is similar to the find() method but raises a ValueError if the substring is not found, while find() returns -1. This can be helpful ...
๐ŸŒ
Reddit
reddit.com โ€บ r/javahelp โ€บ how to quickly get index of given string?
r/javahelp on Reddit: How to quickly get index of given string?
September 30, 2021 -

If I have this

String[] days = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};

And I am passed a three letter day like the above at random. How can I instantly access the index? Or would I just need a regular for loop to run check every one to see if it matches?

Like if I am passed "Wed" I want to know that it is index 2.

Top answer
1 of 3
5
You could use an ArrayList and its indexOf(Object) method https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html#indexOf-java.lang.Object- which returns the int index of the first occurrence of the object in the list, in this case all objects are unique so it would work. Although under the hood it is simply looping: /** * Returns the lowest index at which element appears in this List, or * -1 if it does not appear. * * @param e the element whose inclusion in the List is being tested * @return the index where e was found */ public int indexOf(Object e) { for (int i = 0; i < size; i++) if (equals(e, data[i])) return i; return -1; } https://developer.classpath.org/doc/java/util/ArrayList-source.html
2 of 3
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.