【问题标题】:how to write a method (decompose) that takes as input a string and returns the array of characters that compose the string in java? [duplicate]如何编写一个方法(分解),将字符串作为输入并返回在java中组成字符串的字符数组? [复制]
【发布时间】:2021-05-21 17:05:29
【问题描述】:

提示:

表达式 s.charAt(i) 返回字符串 s 的位置 i 处的字符。

测试:

String word = "Hello";
System.out.println("The word \""+word+"\" decomposes as "+Arrays.toString(decomposeString(word)));

结果:

单词“Hello”分解为[h, e, l, l, o]

【问题讨论】:

    标签: java arrays netbeans decomposition


    【解决方案1】:

    您可以为此使用.toCharArray() 方法。

    示例

    String str = "Hello";
    char[] ch = str.toCharArray();
    

    More information

    【讨论】:

      猜你喜欢
      • 2012-04-03
      • 2012-10-27
      • 1970-01-01
      • 2019-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多