- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to access character of a string
To access character of a string in Java, use the charAt() method. The position is to be added as the parameter.
Let’s say we have the following string −
String str = "laptop";
Let’s find the character at the 4th position using charAt() method.
str.charAt(3));
The following is the final example.
Example
public class Demo { public static void main(String[] args) { String str = "laptop"; System.out.println("String: "+str); // finding character at 4th position System.out.println("Character at 4th position: "+str.charAt(3)); } }
Output
String: laptop Character at 4th position: t
Advertisements