Java StringBuffer char charAt(int index)方法与示例
StringBuffer類char charAt(int index) (StringBuffer Class char charAt(int index))
This method is available in package java.lang.StringBuffer.charAt(int index).
軟件包java.lang.StringBuffer.charAt(int index)中提供了此方法。
This method is used to return the character value at the specified index in the method.
此方法用于返回方法中指定索引處的字符值。
This method raises IndexOutOfBoundsException if the given index is negative or greater than the length of the StringBuffer object.
如果給定的索引為負或大于StringBuffer對象的長度,則此方法引發IndexOutOfBoundsException 。
Syntax:
句法:
char charAt(int index){}Parameter(s):
參數:
We can pass only one object in the method of the StringBuffer i.e index.
我們只能在StringBuffer的方法(即索引)中傳遞一個對象。
Return value:
返回值:
The return type of this method is char that means this method return a character at the given index.
該方法的返回類型為char ,這意味著該方法在給定索引處返回一個字符。
Java程序演示charAt(int index)方法的示例 (Java program to demonstrate example of charAt(int index) method)
import java.lang.StringBuffer;public class StringBufferClass {public static void main(String[] args) {StringBuffer sb = new StringBuffer("Java is a programming language : ");// use charAt(int index) it will return character at the specified index// Display result after implementing charAt(2)System.out.println("The result will be after implementing method charAt(2) is :" + sb.charAt(2));sb = new StringBuffer("Java Support OOPS Concept");// use charAt(int index) it will return character at the specified index// Display result after implementing charAt(5)System.out.println("The result will be after implementing method charAt(5) is :" + sb.charAt(5));} }Output
輸出量
D:\Programs>javac StringBufferClass.javaD:\Programs>java StringBufferClass The result will be after implementing method charAt(2) is :v The result will be after implementing method charAt(5) is :S翻譯自: https://www.includehelp.com/java/stringbuffer-char-charat-int-index-method-with-example.aspx
總結
以上是生活随笔為你收集整理的Java StringBuffer char charAt(int index)方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: “谬从云雨浮”上一句是什么
- 下一篇: 蚂蝗多少钱一斤啊?