相关文章推荐
长情的台灯  ·  陕西高校专升本招生普通本科及职教本科征集志愿 ...·  6 月前    · 
会搭讪的大葱  ·  生态环境部召开1月例行新闻发布会_中华人民共 ...·  1 年前    · 
坚韧的凉面  ·  浙江省教育收费政策(2022年)·  1 年前    · 
发怒的楼房  ·  天理学术|张志明&鲁统部教授团队在异双核团簇 ...·  1 年前    · 
玩足球的筷子  ·  “暮云”:小孩子两岁4个月,现在很喜欢看手机 ...·  1 年前    · 
小百科  ›  Java String charAt() Method - GeeksforGeeks
python string history
谦虚好学的紫菜
2 年前
  • Courses
    • DSA to Development
    • For Working Professionals
      • Data Structure & Algorithm Classes (Live)
      • System Design (Live)
      • JAVA Backend Development(Live)
      • DevOps(Live)
      • Data Structures & Algorithms in Python
    • For Students
      • Interview Preparation Course
      • GATE CS & IT 2024
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced(C++/JAVA)
      • Master Competitive Programming(Live)
      • Full Stack Development with React & Node JS(Live)
    • For School Students
      • CBSE Class 12 Computer Science
      • School Guide
      • Python Programming Foundation
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
      • DSA for Beginners
      • Data Structures
        • Arrays
        • Matrix
        • Strings
        • Linked List
          • Singly Linked List
          • Doubly Linked List
          • Circular Linked List
          • Doubly Circular Linked List
          • Linked List Tutorial
        • Stack
        • Queue
        • Tree
          • Generic Tree
          • Binary Tree
          • Binary Search Tree
          • AVL Tree
          • B Tree
          • B+ Tree
          • Red Black Tree
          • Tree Data Structure Tutorial
        • Heap
        • Hashing
        • Graph
        • Set Data Structure
        • Map Data Structure
        • Advanced Data Structure
        • Data Structures Tutorial
      • Algorithms
        • Analysis of Algorithms
          • Design and Analysis of Algorithms
          • Asymptotic Analysis
          • Asymptotic Notations
          • Worst, Average and Best Cases
        • Searching Algorithms
          • Linear Search
          • Binary Search
          • Searching Algorithms Tutorial
        • Sorting Algorithms
          • Selection Sort
          • Bubble Sort
          • Insertion Sort
          • Merge Sort
          • Quick Sort
          • Heap Sort
          • Counting Sort
          • Radix Sort
          • Bucket Sort
          • Sorting Algorithms Tutorial
        • Greedy Algorithms
        • Dynamic Programming
        • Graph Algorithms
        • Pattern Searching
        • Recursion
        • Backtracking
        • Divide and Conquer
        • Mathematical Algorithms
        • Geometric Algorithms
        • Bitwise Algorithms
        • Randomized Algorithms
        • Branch and Bound
        • Algorithms Tutorial
      • Complete DSA Tutorial
      • Competitive Programming
      • Company Wise SDE Sheets
        • Facebook SDE Sheet
        • Amazon SDE Sheet
        • Apple SDE Sheet
        • Netflix SDE Sheet
        • Google SDE Sheet
        • Wipro Coding Sheet
        • Infosys Coding Sheet
        • TCS Coding Sheet
        • Cognizant Coding Sheet
        • HCL Coding Sheet
      • DSA Cheat Sheets
        • DSA Sheet for Beginners
        • SDE Sheets
        • FAANG Coding Sheet
        • Love Babbaar Sheet
        • Mass Recruiter Sheet
        • Product-Based Coding Sheet
        • Company-Wise Preparation Sheet
      • Top Interview Questions
        • Top 100 DSA Interview Questions Topic-wise
        • Top 50 Array Problems
        • Top 50 String Problems
        • Top 50 Stack Problems
        • Top 50 Heap Problems
        • Top 50 Linked List Problems
        • Top 50 Tree Problems
        • Top 50 Graph Problems
        • Top 50 Problems on Recursion Algorithms
        • Top 20 Interview Questions on Greedy Algorithms
        • Top 20 Interview Questions on Dynamic Programming
        • Top 50 Problems on Dynamic Programming (DP)
        • Top 20 Interview Questions on Hashing
        • Interview Questions on Top 10 Algorithms
        • Commonly Asked Data Structure Interview Questions
      • DSA Blogs
      • Puzzles
        • All Puzzles
        • Top 100 Puzzles Asked In Interviews
        • Top 20 Puzzles Commonly Asked During SDE Interviews
        • Top MCQs on Puzzles with Answers
        • Crossword Puzzle Of The Week
    • ML & Data Science
      • Learn Python
      • Machine Learning
        • Machine Learning Tutorial
        • Maths for ML
        • ML Projects
      • Data Science using Python
      • Data Science using R
      • Data Science Packages
        • Pandas Tutorial
        • NumPy Tutorial
      • Data Visualization
        • Data Visualization with Python
          • Python Data Visualization Tutorial
          • Matplotlib Tutorial
          • Bokeh Tutorial
          • Plotly Tutorial
          • Seaborn Tutorial
        • Data Visualization with R
          • Data Visualization with R
          • Plotly Tutorial
          • ggplot Tutorial
        • Data Visualization Tools
          • Tableau
          • Power BI
      • Data Analysis
        • Data Analysis with Python
        • Data Analysis with R
      • Deep Learning
        • Deep Learning Tutorial
        • Deep Learning Projects
      • NLP Tutorial
      • OpenCV Tutorial
      • Interview Questions
        • Machine Learning Interview Question
        • Deep Learning Interview Question
        • Python Interview Questions
        • Top 50 R Interview Questions
      • ML Frameworks
        • Tensorflow
        • PyTorch
        • PyTorch Lightning
    • System Design
      • System Design Tutorial
        • What is System Design
        • Key Terminologies in System Design
        • Analysis and Architecture of Systems
        • Scalability in System Design
        • Databases in System Design
        • High Level Design or HLD
        • Low Level Design or LLD
        • Communication Protocols
        • Web Servers and Proxies
        • Case Studies in Designing Systems
        • Complete System Design Tutorial
      • Software Design Patterns
        • Factory Pattern
        • Observer Pattern
        • Singleton Design Pattern
        • Decorator Pattern
        • Strategy Pattern
        • Adapter Pattern
        • Command Pattern
        • Iterator Pattern
        • Prototype Design Pattern
        • All Design Patterns
      • System Design Roadmap
      • Top 10 System Design Interview Questions and Answers
    • Interview Corner
      • Company Preparation
      • Top Topics
      • Practice Company Questions
      • Interview Experiences
      • Experienced Interviews
      • Internship Interviews
      • Competitive Programming
      • Multiple Choice Quizzes
      • Aptitude for Placements
    • Languages
      • C
      • C++
      • Java
      • Python
      • JavaScript
      • PHP
      • R Tutorial
      • C#
      • SQL
      • Scala
      • Perl
      • Go Language
      • Kotlin
    • Web Development
      • HTML
        • HTML Tutorial
        • Free HTML Course
        • HTML Cheat Sheet
      • CSS
        • CSS Tutorial
        • Free CSS Course
        • CSS Cheat Sheet
        • CSS Preprocessors
          • SASS
          • LESS
      • JavaScript
        • JavaScript Tutorial
        • JavaScript Programs
        • JavaScript Questions
        • JavaScript Cheat Sheet
        • DSA using JavaScript
        • Free JavaScript Course
        • JavaScript A to Z Complete Guide
      • ReactJS
        • ReactJS Tutorial
        • Free ReactJS Course
        • ReactJS Frameworks
          • NextJS
          • React Material UI
          • React Bootstrap
          • React Suite
          • Ant Design
          • ReactJS Reactstrap
          • BlueprintJS
      • Node.js
        • Node.js Tutorial
        • Express.js
      • PHP
        • PHP Tutorial
        • PHP Programming Examples
      • AngularJS
        • AngularJS Tutorial
        • AngularJS Cheat Sheet
        • AngularJS Frameworks
          • Angular PrimeNG
          • Angular ngx Bootstrap
      • jQuery
        • jQuery Tutorial
        • jQuery Cheat Sheet
        • jQuery Frameworks
          • jQuery UI
          • jQuery Mobile
          • jQwidget
      • TypeScript
      • JSON
      • CSS Frameworks & Libraries
        • Bootstrap
          • Bootstrap Tutorial
          • Bootstrap 5
          • Bootstrap Cheat Sheet
        • Tailwind CSS
        • Bulma
        • Pure CSS
        • Materialize CSS
        • Foundation
        • Semantic UI
        • Primer CSS
        • Spectre CSS
      • JS Other Frameworks & Libraries
        • Lodash
        • D3.js
        • Vue.js
        • Underscore.js
        • TensorFlow.js
        • Collect.js
        • Fabric.js
        • p5.js
    • CS Subjects
      • Mathematics
      • Operating System
      • DBMS
      • Computer Networks
      • Computer Organization and Architecture
      • Theory of Computation
      • Compiler Design
      • Digital Logic
      • Software Engineering
    • DevOps
      • GIT
      • AWS
      • Docker
      • Kubernetes
      • Microsoft Azure Tutorial
      • Google Cloud Platform
    • School Learning
      • English Grammar
      • School Programming
      • Mathematics
        • Number System
        • Algebra
        • Linear Algebra
        • Trigonometry
        • Set Theory
        • Statistics
        • Probability
        • Geometry
        • Mensuration
        • Logarithms
        • Calculus
      • CBSE Syllabus
        • Class 8 Syllabus
        • Class 9 Syllabus
        • Class 10 Syllabus
        • Class 11 Syllabus
        • Class 12 Syllabus
      • Maths Notes (Class 8-12)
        • Class 8 Notes
        • Class 9 Notes
        • Class 10 Notes
        • Class 11 Notes
        • Class 12 Notes
      • Maths Formulas (Class 8 -11)
        • Class 8 Formulas
        • Class 9 Formulas
        • Class 10 Formulas
        • Class 11 Formulas
      • Math Calculators
      • NCERT Solutions
        • Class 8 Maths Solution
        • Class 9 Maths Solution
        • Class 10 Maths Solution
        • Class 11 Maths Solution
        • Class 12 Maths Solution
      • RD Sharma Solutions
        • Class 8 Maths Solution
        • Class 9 Maths Solution
        • Class 10 Maths Solution
        • Class 11 Maths Solution
        • Class 12 Maths Solution
      • Science Notes
        • Class 8 Notes
        • Class 9 Notes
        • Class 10 Notes
      • Physics Notes (Class 8-12)
        • Class 8 Notes
        • Class 9 Notes
        • Class 10 Notes
        • Class 11 Notes
        • Class 12 Notes
      • Chemistry Notes (Class 8-12)
        • Class 8 Notes
        • Class 9 Notes
        • Class 10 Notes
        • Class 11 Notes
        • Class 12 Notes
      • Biology Notes (Class 8-12)
        • Class 8
        • Class 9
        • Class 10
        • Class 11
        • Class 12
      • Social Science Syllabus
        • Class 7 SS Syllabus
        • Class 8 SS Syllabus
        • Class 9 SS Syllabus
        • Class 10 SS Syllabus
      • Social Science Notes
        • SS Notes (Class 7-12)
          • Class 7 Notes
          • Class 8 Notes
          • Class 9 Notes
          • Class 10 Notes
        • CBSE History Notes (Class 7-10)
          • History Class 7
          • History Class 8
          • History Class 9
        • CBSE Geography Notes (Class 7-10)
          • Geo. Class 7
          • Geo. Class 8
          • Geo. Class 9
        • CBSE Civics Notes (Class 7-10)
          • Civics Class 7
          • Civics Class 8
      • CBSE Previous Year Papers
        • Maths
        • Physics
        • History
        • Georgraphy
        • Political Science
        • Economics
    • Commerce
      • Business Studies
        • Class 11th Notes
        • Class 12th Notes
        • Business Studies Complete Guide
      • Accountancy
        • Class 11th Notes
        • Class 12th Notes
        • Accountancy Complete Guide
      • Microeconomics
        • Class 11th Notes
        • Microeconomics Complete Guide
      • Statistics for Economics
        • Class 11th Notes
        • Statistics for Economics Complete Guide
      • Macroeconomics
        • Class 12th notes
        • Macroeconomics Complete Guide
      • Indian Economic Development
        • Class 12th Notes
        • Indian Economic Development Complete Guide
      • Human Resource Management (HRM)
      • Management
      • Income Tax
      • Finance
      • Commerce Complete Guide
    • GATE
      • GATE 2024 Live Course
      • GATE Computer Science Notes
      • Last Minute Notes
      • GATE CS Solved Papers
      • GATE CS Original Papers and Official Keys
      • GATE CS 2023 Syllabus
      • Important Topics for GATE CS
      • GATE 2023 Important Dates
      • Other CS Exams
        • ISRO
          • ISRO CS Original Papers and Official Keys
          • ISRO CS Solved Papers
          • ISRO CS Syllabus for Scientist/Engineer Exam
        • UGC NET
          • UGC NET CS Notes Paper II
          • UGC NET CS Notes Paper III
          • UGC NET CS Solved Papers
    • Banking Exams Study Material
      • RRB Clerk 2023 Exam
      • SBI Clerk
        • SBI Clerk Syllabus
        • General Awareness
        • English
        • Quantitative Aptitude
        • Reasoning Ability
        • SBI Clerk Practice Papers
      • SBI PO
        • SBI PO Syllabus
        • General Awareness
        • English
        • Quantitative Aptitude
        • Reasoning Ability
        • Previous Year Papers
        • SBI PO Practice Papers
      • IBPS PO
        • IBPS PO 2022 Syllabus
        • English Notes
        • Reasoning Notes
        • Previous Year Papers
        • Mock Question Papers
        • General Awareness
      • IBPS Clerk
        • IBPS Clerk Syllabus
        • English Notes
        • Previous Year Papers
    • UPSC Study Material
      • Geography Notes
      • History Notes
        • Modern Indian History Notes
        • Medieval Indian History Notes
        • Ancient Indian History Notes
        • Complete History Notes
      • Science & Tech. Notes
      • Ethics Notes
      • Polity Notes
      • Economics Notes
      • Government Schemes (Updated)
      • UPSC Previous Year Papers
    • SSC CGL Study Material
      • SSC CGL Syllabus
      • General Studies
      • English
      • Reasoning
      • Subjectwise Practice Papers
      • Previous Year Papers
    • SEO-Search Engine Optimization
      • What is SEO
      • Search Engine Optimization Basics
      • Types of SEO
      • Keyword Optimization in SEO
      • Backlinks in SEO
      • SEO Blogs
      • Mobile SEO
      • SEO Complete Reference
    • Student
      • Campus Ambassador Program
      • School Ambassador Program
      • Project
      • Geek of the Month
      • Campus Geek of the Month
      • Placement Course
      • Competitive Programming
      • Testimonials
      • Student Chapter
      • Geek on the Top
      • Internship
      • Careers
  • Jobs
    • For Job Seekers
      • Get Hired: Apply for Jobs
      • Job-a-thon: Hiring Challenge
    • For Recruiters
      • Corporate Hiring Solutions
  • Practice
    • All DSA Problems
    • Problem of the Day
    • GFG SDE Sheet
    • Curated DSA Lists
      • Beginner's DSA Sheet
      • Love Babbar Sheet
      • Top 50 Array Problems
      • Top 50 String Problems
      • Top 50 DP Problems
      • Top 50 Graph Problems
      • Top 50 Tree Problems
  • Contests
    • World Cup Hack-A-Thon
    • GFG Weekly Coding Contest
    • Job-A-Thon: Hiring Challenge
    • BiWizard School Contest
    • All Contests and Events
    • Write an Interview Experience
    • Java String compareTo() Method with Examples
    • Java String join() with examples
    • Java String getChars() with examples
    • String startswith() Method in Java with Examples
    • Java String toCharArray() with example
    • Java String endsWith() with examples
    • Java String trim() Method
    • Java.lang.String.lastIndexOf() Method
    • Java String equalsIgnoreCase() Method with Examples
    • Java String indexOf()
    • Java.lang.string.replace() method in Java
    • Java String isEmpty() method with example
    • StringBuffer insert() in Java
    • String matches() Method in Java with Examples
    • Split() String method in Java with examples
    • Substring in Java
    • StringBuffer reverse() Method in Java with Examples
    • Number.floatValue() method in java with examples
    • Java String concat() Method
    • Write an Interview Experience
    • Java String compareTo() Method with Examples
    • Java String join() with examples
    • Java String getChars() with examples
    • String startswith() Method in Java with Examples
    • Java String toCharArray() with example
    • Java String endsWith() with examples
    • Java String trim() Method
    • Java.lang.String.lastIndexOf() Method
    • Java String equalsIgnoreCase() Method with Examples
    • Java String indexOf()
    • Java.lang.string.replace() method in Java
    • Java String isEmpty() method with example
    • StringBuffer insert() in Java
    • String matches() Method in Java with Examples
    • Split() String method in Java with examples
    • Substring in Java
    • StringBuffer reverse() Method in Java with Examples
    • Number.floatValue() method in java with examples
    • Java String concat() Method

    The Java String charAt() method returns the character at the specified index. The index value should lie between 0 and length() – 1. Let us check more points about the String charAt() method in Java.

    Syntax of charAt() Java method

    public char charAt(int index)

    Parameters

  • index: Index of the character to be returned.
  • Return Type

  • Returns the character at the specified position.
  • Exceptions

  • StringIndexOutOfBoundsException – If the index is negative or greater than the length of the String.
  • Example of Java String charAt()

    The following examples demonstrate how to use charAt() method:

    Example 1:

    To show the working of the charAt() method

    public static void main(String args[])
    String s = "Welcome! to Geeksforgeeks Planet" ;
    char ch = s.charAt( 3 );
    System.out.println(ch);
    ch = s.charAt( 0 );
    System.out.println(ch);

    Output

    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 4
        at java.lang.String.charAt(String.java:658)
        at Gfg.main(File.java:9)

    Programs for charAt Java Method

    1. Accessing the First and Last Character using the charAt() Java method

    2. Print Characters Presented at Odd Positions and Even Positions using charAt() Java method

    // Java Program to implement
    // Print Characters Presented at
    // Odd Positions and Even Positions
    import java.io.*;
    // Driver Class
    class GFG {
    // main function
    public static void main(String[] args)
    String str = "GeeksforGeeks" ;
    // Odd Positions
    System.out.println( "Odd Positions" );
    for ( int i = 0 ; i < str.length(); i += 2 ) {
    System.out.print(str.charAt(i));
    System.out.println( "\n" );
    // Even Positions
    System.out.println( "Even Positions" );
    for ( int i = 1 ; i < str.length(); i += 2 ) {
    System.out.print(str.charAt(i));
    for ( int i = 0 ; i < str.length(); i++) {
    // Counting e in string
    if (str.charAt(i) == 'e' )
    count++;
    // printing occurrence
    System.out.println( "Count the occurrence of e : "
    + count);
    • Company
    • About Us
    • Legal
    • Careers
    • In Media
    • Contact Us
    • Advertise with us
    • Campus Training Program
    • Explore
    • Job-A-Thon Hiring Challenge
    • Hack-A-Thon
    • GfG Weekly Contest
    • Offline Classes (Delhi/NCR)
    • DSA in JAVA/C++
    • Master System Design
    • Master CP
    • Languages
    • Python
    • Java
    • C++
    • PHP
    • GoLang
    • SQL
    • R Language
    • Android Tutorial
    • DSA Concepts
    • Data Structures
    • Arrays
    • Strings
    • Linked List
    • Algorithms
    • Searching
    • Sorting
    • Mathematical
    • Dynamic Programming
    • DSA Roadmaps
    • DSA for Beginners
    • Basic DSA Coding Problems
    • DSA Roadmap by Sandeep Jain
    • DSA with JavaScript
    • Top 100 DSA Interview Problems
    • All Cheat Sheets
    • Web Development
    • HTML
    • CSS
    • JavaScript
    • Bootstrap
    • ReactJS
    • AngularJS
    • NodeJS
    • Express.js
    • Lodash
    • Computer Science
    • GATE CS Notes
    • Operating Systems
    • Computer Network
    • Database Management System
    • Software Engineering
    • Digital Logic Design
    • Engineering Maths
    • Python
    • Python Programming Examples
    • Django Tutorial
    • Python Projects
    • Python Tkinter
    • OpenCV Python Tutorial
    • Python Interview Question
    • Data Science & ML
    • Data Science With Python
    • Data Science For Beginner
    • Machine Learning Tutorial
    • Maths For Machine Learning
    • Pandas Tutorial
    • NumPy Tutorial
    • NLP Tutorial
    • Deep Learning Tutorial
    • DevOps
    • Git
    • AWS
    • Docker
    • Kubernetes
    • Azure
    • GCP
    • Competitive Programming
    • Top DSA for CP
    • Top 50 Tree Problems
    • Top 50 Graph Problems
    • Top 50 Array Problems
    • Top 50 String Problems
    • Top 50 DP Problems
    • Top 15 Websites for CP
    • System Design
    • What is System Design
    • Monolithic and Distributed SD
    • Scalability in SD
    • Databases in SD
    • High Level Design or HLD
    • Low Level Design or LLD
    • Top SD Interview Questions
    • Interview Corner
    • Company Wise Preparation
    • Preparation for SDE
    • Experienced Interviews
    • Internship Interviews
    • Competitive Programming
    • Aptitude Preparation
    • GfG School
    • CBSE Notes for Class 8
    • CBSE Notes for Class 9
    • CBSE Notes for Class 10
    • CBSE Notes for Class 11
    • CBSE Notes for Class 12
    • English Grammar
    • Commerce
    • Accountancy
    • Business Studies
    • Economics
    • Human Resource Management (HRM)
    • Management
    • Income Tax
    • Finance
    • Statistics for Economics
    • UPSC
    • Polity Notes
    • Geography Notes
    • History Notes
    • Science and Technology Notes
    • Economics Notes
    • Important Topics in Ethics
    • UPSC Previous Year Papers
    • SSC/ BANKING
    • SSC CGL Syllabus
    • SBI PO Syllabus
    • SBI Clerk Syllabus
    • IBPS PO Syllabus
    • IBPS Clerk Syllabus
    • Aptitude Questions
    • SSC CGL Practice Papers
    • Write & Earn
    • Write an Article
    • Improve an Article
    • Pick Topics to Write
    • Write Interview Experience
    • Internships
    @GeeksforGeeks, Sanchhaya Education Private Limited , All rights reserved We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy Got It !
    Please go through our recently updated Improvement Guidelines before submitting any improvements.
    This article is being improved by another user right now. You can suggest the changes for now and it will be under the article's discussion tab.
    You will be notified via email once the article is available for improvement. Thank you for your valuable feedback!
    Please go through our recently updated Improvement Guidelines before submitting any improvements.
    Suggest Changes
    Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
 
推荐文章
长情的台灯  ·  陕西高校专升本招生普通本科及职教本科征集志愿 - 西部网(陕西新闻网)
6 月前
会搭讪的大葱  ·  生态环境部召开1月例行新闻发布会_中华人民共和国生态环境部
1 年前
坚韧的凉面  ·  浙江省教育收费政策(2022年)
1 年前
发怒的楼房  ·  天理学术|张志明&鲁统部教授团队在异双核团簇催化剂合成领域取得重要进展-天津理工大学
1 年前
玩足球的筷子  ·  “暮云”:小孩子两岁4个月,现在很喜欢看手机和平板,我们几乎没法阻止。请问一下,使用手机、平板会导致近视吗?有没有什么办法可以减少孩子看手机和平板的时间?- 四川省人民政府网站
1 年前
Link管理   ·   Sov5搜索   ·   小百科
小百科 - 百科知识指南