zoukankan      html  css  js  c++  java
  • Java String getChars()方法

    语法

    以下是此方法的语法

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

    参数

    • srcBegin - 要复制的字符串中第一个字符的索引。
    • srcEnd - 要复制的字符串中最后一个字符后面的索引。
    • dst - 目标数组。
    • dstBegin - 目标数组中的起始偏移量。

    返回值

    • 它不返回任何值,但可能会抛出IndexOutOfBoundsException
    示例
     1 import java.io.*;
     2 
     3 public class Test {
     4 
     5     public static void main(String args[]) {
     6         String Str1 = new String("Welcome to Yiibai.com");
     7         char[] Str2 = new char[7];
     8         try {
     9             Str1.getChars(8, 15, Str2, 0);
    10             System.out.print("Copied Value = ");
    11             System.out.println(Str2);
    12         } catch (Exception ex) {
    13             System.out.println("Raised exception...");
    14         }
    15     }
    16 }

    执行上面示例代码,得到以下结果:

    Copied Value = to Yiib
    作者: celin_Angel Java技术QQ群:227270512 / Linux QQ群:479429477
    原文出自【易百教程】,商业转载请联系作者获得授权,非商业转载请保留原文链接:https://www.yiibai.com/java/java_string_getchars.html
  • 相关阅读:
    替换空格
    centos虚拟机 服务器搭建
    Java 深度遍历和广度优先遍历
    idea热部署Devtools
    idea字符编码设置
    idea破解详细教程
    Java序列化
    60+Git常用命令行
    LeetCode 236. 二叉树的最近公共祖先
    08 讲解v-cloak,v-text,v-html的基本使用
  • 原文地址:https://www.cnblogs.com/it-deepinmind/p/13230164.html
Copyright © 2011-2022 走看看