getchars_Java String getChars()方法与示例

getchars

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

getChars() is a String method in Java and it is used to get the number of characters from the given index from the string.

getChars()是Java中的String方法,用于从字符串的给定索引中获取字符数。

It extracts the part of the string and stores to the character array. If an index is of out of range – it returns an exception.

它提取字符串的一部分并存储到字符数组。 如果索引超出范围–它返回一个异常。

Syntax:

句法:

    void source_string.getChars(
        srcStartIndex, 
        srcEndIndex, 
        target_charArray, 
        targetStartIndex);

Here,

这里,

  • source_string is a string from where we have to get the characters.

    source_string是我们必须从中获取字符的字符串。

  • srcStartIndex is the starting position in the source_string.

    srcStartIndex是source_string中的起始位置。

  • srcEndIndex is the ending position in the source_string.

    srcEndIndex是source_string中的结束位置。

  • target_charArray is the output/targeted array in which we have store the copied characters.

    target_charArray是输出/目标数组,我们在其中存储了复制的字符。

  • targetStartIndex is the start position in the target_charArray.

    targetStartIndex是target_charArray中的起始位置。

Example:

例:

    Input: 
    str = "Welcome at IncludeHelp"

    Function call:
    input.getChars(11, 22, output_str, 0);

    Output:
    output_str = "IncludeHelp"

Java code to get the characters from a string using String.getChars() method

Java代码使用String.getChars()方法从字符串中获取字符

public class Main
{
    public static void main(String[] args) {
        String input = new String("Welcome at IncludeHelp");
        char[] output = new char[11];
        
        //here, we are going to get IncludeHelp from the String
        //IncludeHelp is written from 11th 
        input.getChars(11, 22, output, 0);
        
        System.out.println("input  = " + input);
        System.out.println("output = " + String.valueOf(output));
    }
}

Output

输出量

input  = Welcome at IncludeHelp
output = IncludeHelp


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

getchars

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值