开发手册 欢迎您!
软件开发者资料库

Java String getChars() 方法

Java有一组可以用于字符串的内置方法。Java 字符串(String)操作常用操作,如字符串的替换、删除、截取、赋值、连接、比较、查找、分割等。本文主要介绍Java String getChars() 方法。

Java 字符串方法

例如:

public class Test {    public static void main(String args[]) {        String Str1 = new String("www.wonhero.com");        char[] Str2 = new char[7];        try {            Str1.getChars(4, 11, Str2, 0);            System.out.println(Str2 );        } catch( Exception ex) {           ex.printStackTrace();        }    }}

1、定义和用法

getChars() 方法将字符从字符串复制到目标字符数组。

2、调用语法

public void getChars(int srcBegin, int srcEnd, char[] dst,  int dstBegin)

3、参数说明

参数

描述

srcBegin

字符串中要复制的第一个字符的索引

srcEnd

字符串中要复制的最后一个字符之后的索引

dst

目标数组

dstBegin

目标数组中的起始偏移量

Java 字符串方法