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.mzph.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(双向队列)操作以及…