string charat_Java String charAt()方法與示例

string charat

字符串charAt()方法 (String charAt() Method)

charAt() method is a String class method in Java, it is used to get the character from specified index from a given string.

charAt()方法是Java中的String類方法,用于從給定字符串的指定索引中獲取字符。

Syntax:

句法:

    char String.charAt(index);

It accepts an index and returns the characters from the specified position of the String.

它接受索引并從String的指定位置返回字符。

Note: If the index is out of range, the method returns "String index out of range" exception.

注意:如果索引超出范圍,則該方法將返回“字符串索引超出范圍”異常。

Example:

例:

    Input:
str = "includeHelp"
Function call:
str.charAt(0)
Output:
"i"

Code:

碼:

public class Main
{
public static void main(String[] args) {
String str = "includeHelp";
System.out.println("character at 0 index: " + str.charAt(0));
System.out.println("character at 1 index: " + str.charAt(1));
System.out.println("character at 2 index: " + str.charAt(2));
System.out.println("character at 3 index: " + str.charAt(3));
System.out.println("character at 4 index: " + str.charAt(4));
System.out.println("character at 5 index: " + str.charAt(5));
System.out.println("character at 6 index: " + str.charAt(6));
System.out.println("character at 7 index: " + str.charAt(7));
System.out.println("character at 8 index: " + str.charAt(8));
System.out.println("character at 9 index: " + str.charAt(9));
System.out.println("character at 10 index: " + str.charAt(10));
}
}

Output

輸出量

character at 0 index: i
character at 1 index: n
character at 2 index: c
character at 3 index: l
character at 4 index: u
character at 5 index: d
character at 6 index: e
character at 7 index: H
character at 8 index: e
character at 9 index: l
character at 10 index: p

翻譯自: https://www.includehelp.com/java/string-charAt-method-with-example.aspx

string charat

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378419.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378419.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378419.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

opencv模板匹配

matchTemplate函數參數 模板匹配是通過模板在采集到的原圖像進行滑動尋找與模板圖像相似的目標。模板匹配不是基于直方圖的方式,而是基于圖像的灰度匹配。 6種匹配度量方法: 平方差匹配法CV_TM_SQDIFF 歸一化平方差匹配法CV_TM_SQDIFF_NORMED 相關匹配…

Java程序設計4——集合類

1 JAVA集合概述 Java集合封裝了一系列數據結構比如鏈表、二叉樹、棧、隊列等,然后提供了針對這些數據結構的一系列算法比如查找、排序、替換,使編程難度大大降低。(這句話有可能是非法…

Python中的a+=a和a=a+a的區別(認真看完后,我相信你一定會回來感謝我的)

一、先來兩段代碼! a 100def beyond(num):numnumprint(num)beyond(a)#結果為:200 print(a)#結果為:100a 100def beyond(num):numnumnumprint(num)beyond(a)#結果為:200 print(a)#結果為:100通過這兩段代碼的結果可以…

安裝linux后win7引導程序,安裝Windows7+Ubuntu+CentOS三系統之后的引導問題

依次安裝了Windows7、Ubuntu12.04、CentOS6.3系統后,開機引導項只有CentOS和Other(即Windows7)兩個選項,無法進入Ubuntu系統,所以利用Ubuntu的LiveCD光盤啟動后進行如下操作對grub進行修復,步驟如下:啟動Live CD&#…

Web之神php

我開始學習做網頁的時候用的是asp,后來轉行用php。以前只知道php很好學,并且很方便。我學習php的時候關于php的書種類很少好像那時候我在當當上面只看到3本,跟現在沒法比,現在大家再學習php就簡單多了,那么多書那么多資料。 現在我…

python與tensorflow知識點截圖集錦(持續囤積)

目錄前言conda環境管理python語法【1】語言屬性【2】代碼縮進問題【3】input和output函數與print函數【4】關鍵字與簡單數據類型與簡單運算符【5】利用縮進體現邏輯關系【6】數據結構:列表與元組【7】數據結構:字典【8】數據結構:集合【8】基…

string concat_Java String concat()方法與示例

string concat字符串concat()方法 (String concat() Method) concat() is a String method in Java and it is used to concatenate (add) a given string to the string. It returns a concatenated string. concat()是Java中的String方法,用于將給定的字符串連接(…

第五章 染料結構對染色性能的影響單元測驗

?1,引起染料結構發生變化的因素有() 染料商品添加劑及方法。 染料合成中間體選擇及合成條件。 染色助劑。 染色溫度。 2,染料結構影響染色()性能 染色熱力學性能。 染色牢度。 染色動力學性能。 染色勻染性能。 3,染料精制除雜時,染液中加入的溶劑應該具有()性能 …

sql2008怎么轉移到sql2005

一般來說,最新版本會向下兼容,如果舊版本想用新版本則不行。 但是還是有一些辦法的,可以參考一下。-- 對象資源管理器(沒有的話按F8) 連接到你的2008實例--右鍵你要降級的數據庫-- 任務-- 生成腳本-- 在隨后出現的腳本中, 單擊"下一步&q…

字符搜索正則表達式語法詳解

工作之余抽點時間出來寫寫博文,希望對新接觸的朋友有幫助。明天在這里和大家一起學習一下字符搜索 作為一個術技,時常會到碰正則表達式相干的西東,很多時候忙著趕進度,都是在網上找一個可以決解的正則表達式,或是換另外…

gRPC之grpc resolver

1、grpc resolver 當我們的服務剛剛成型時,可能一個服務只有一臺實例,這時候client要建立grpc連接很簡單,只需要指定server 的ip就可以了。但是,當服務成熟了,業務量大了,這個時候,一個實例就…

linux測試固態硬盤讀寫速度,在 Linux 上檢測 IDE/SATA SSD 硬盤的傳輸速度

你知道你的硬盤在 Linux 下傳輸有多快嗎?不打開電腦的機箱或者機柜,你知道它運行在 SATA I (150 MB/s) 、 SATA II (300 MB/s) 還是 SATA III (6.0Gb/s) 呢?你能夠使用 hdparm 和 dd 命令來檢測你的硬盤速度。它為各種硬盤的 ioctls 提供了命…

stl標準模板庫_C ++標準模板庫(STL)中的array :: fill()

stl標準模板庫fill() is a member function of "array container", which sets a given value to all array elements. It can also be used to set the value to other of containers also. Value type should be same as container type. fill()是“數組容器”的成…

Opencv——批量處理同一文件夾下的圖片(解決savedfilename = dest + filenames[i].substr(len)問題)

文章目錄前言一、完整代碼二、實現效果前言 第一份代碼實現了批量修改同一文件夾下圖片的尺寸,有其他需求時僅需修改處理部分的代碼以及文件夾路徑。 第二份代碼實現了批量截取同一文件夾下每張圖片的ROI區域作為結果保存,注意截取后按下enter鍵才會跳到…

linux統計文件目錄及其文件個數

linux下統計目錄及其子目錄的文件的個數 查看某目錄下文件的個數 ls -l |grep "^-"|wc -l或find ./company -type f | wc -l 查看某目錄下文件的個數,包括子目錄里的。 ls -lR|grep "^-"|wc -l查看某文件夾下目錄的個數,包括子目錄里…

處理文件、攝像頭和圖形用戶界面

1、基本I/O腳本 1.1 讀/寫圖像文件 import numpy import cv2#利用二維Numpy數組簡單創建一個黑色的正方形圖像 img numpy.zeros((3,3),dtypenumpy.uint8) img #結果為:array([[0, 0, 0],[0, 0, 0],[0, 0, 0]], dtypeuint8)img.shape#結果為:(3, 3)###…

linux桌面天氣,Ubuntu 14.10中安裝和配置天氣應用

對于操作系統平臺而言,有各種小插件功能方便用戶日常應用。在Ubuntu桌面中提供天氣信息的功能,可以使用Unity Dash和桌面應用來獲得相關信息,比如Typhoon。但對于用戶而言,可以提供快速查詢天氣狀況和溫度數據,并且只需…

使用ACE_SOCK_SEQPACK_Association獲取socket連接的本地及遠程IP端口信息

int connect(const std::string& ip, int port){ ACE_INET_Addr portAddr(port, ip.c_str()); ACE_SOCK_Connector connector; ACE_SOCK_Stream peer; if (-1 connector.connect(peer, portAddr)) { std::cout << "連接服務器(" <&…

linux批處理操作系統_批處理操作系統

linux批處理操作系統批處理操作系統 (Batch Processing Operating System) When we are working in an environment there is a restriction of making use of computer resources effectively and improvement in the programmers output. When we are working with tapes a l…

STL容器及其簡單應用(stack、priority_queue、vector、deuqe、list、map/multimap、set/multiset)

目錄前言【1】stack操作以及應用stack的幾個核心接口利用stack完成進制轉換【2】priority_queue操作以及應用priority_queue的幾個核心接口利用priority_queue完成合并果子問題【3】vector操作以及應用vector的幾個核心接口利用vector完成隨機排序【4】deuqe(雙向隊列)操作以及…