• <bdo id='MF4Nr'></bdo><ul id='MF4Nr'></ul>

      <small id='MF4Nr'></small><noframes id='MF4Nr'>

    1. <legend id='MF4Nr'><style id='MF4Nr'><dir id='MF4Nr'><q id='MF4Nr'></q></dir></style></legend>
    2. <tfoot id='MF4Nr'></tfoot>

      1. <i id='MF4Nr'><tr id='MF4Nr'><dt id='MF4Nr'><q id='MF4Nr'><span id='MF4Nr'><b id='MF4Nr'><form id='MF4Nr'><ins id='MF4Nr'></ins><ul id='MF4Nr'></ul><sub id='MF4Nr'></sub></form><legend id='MF4Nr'></legend><bdo id='MF4Nr'><pre id='MF4Nr'><center id='MF4Nr'></center></pre></bdo></b><th id='MF4Nr'></th></span></q></dt></tr></i><div id='MF4Nr'><tfoot id='MF4Nr'></tfoot><dl id='MF4Nr'><fieldset id='MF4Nr'></fieldset></dl></div>

        转换列表&lt;字符串&gt;Java中的字符串[]

        时间:2023-07-27

        • <bdo id='JfRmZ'></bdo><ul id='JfRmZ'></ul>

          1. <i id='JfRmZ'><tr id='JfRmZ'><dt id='JfRmZ'><q id='JfRmZ'><span id='JfRmZ'><b id='JfRmZ'><form id='JfRmZ'><ins id='JfRmZ'></ins><ul id='JfRmZ'></ul><sub id='JfRmZ'></sub></form><legend id='JfRmZ'></legend><bdo id='JfRmZ'><pre id='JfRmZ'><center id='JfRmZ'></center></pre></bdo></b><th id='JfRmZ'></th></span></q></dt></tr></i><div id='JfRmZ'><tfoot id='JfRmZ'></tfoot><dl id='JfRmZ'><fieldset id='JfRmZ'></fieldset></dl></div>

                <tbody id='JfRmZ'></tbody>

              <small id='JfRmZ'></small><noframes id='JfRmZ'>

                  <tfoot id='JfRmZ'></tfoot>
                1. <legend id='JfRmZ'><style id='JfRmZ'><dir id='JfRmZ'><q id='JfRmZ'></q></dir></style></legend>
                2. 本文介绍了转换列表&lt;字符串&gt;Java中的字符串[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如何转换 列表将字符串转换为 数组?以下代码返回错误.

                  How do I convert a list of String into an array? The following code returns an error.

                  public static void main(String[] args) {
                      List<String> strlist = new ArrayList<String>();
                      strlist.add("sdfs1");
                      strlist.add("sdfs2");
                      String[] strarray = (String[]) strlist.toArray();       
                      System.out.println(strarray);
                  }
                  

                  错误:

                  Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
                      at test.main(test.java:10)
                  

                  推荐答案

                  你想要的

                  String[] strarray = strlist.toArray(new String[0]);
                  

                  参见这里 获取文档并注意,您还可以通过填充传递的数组的方式调用此方法,而不仅仅是使用它来计算要返回的类型.另请注意,当您打印数组时,您可能更喜欢

                  See here for the documentation and note that you can also call this method in such a way that it populates the passed array, rather than just using it to work out what type to return. Also note that maybe when you print your array you'd prefer

                  System.out.println(Arrays.toString(strarray));
                  

                  因为这将打印实际的元素.

                  since that will print the actual elements.

                  这篇关于转换列表&lt;字符串&gt;Java中的字符串[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Java将double转换为日期格式 下一篇:Java中从字符串到sql日期的日期转换给出不同的输

                  相关文章

                  最新文章

                    <legend id='n83p0'><style id='n83p0'><dir id='n83p0'><q id='n83p0'></q></dir></style></legend>

                    <i id='n83p0'><tr id='n83p0'><dt id='n83p0'><q id='n83p0'><span id='n83p0'><b id='n83p0'><form id='n83p0'><ins id='n83p0'></ins><ul id='n83p0'></ul><sub id='n83p0'></sub></form><legend id='n83p0'></legend><bdo id='n83p0'><pre id='n83p0'><center id='n83p0'></center></pre></bdo></b><th id='n83p0'></th></span></q></dt></tr></i><div id='n83p0'><tfoot id='n83p0'></tfoot><dl id='n83p0'><fieldset id='n83p0'></fieldset></dl></div>

                    1. <small id='n83p0'></small><noframes id='n83p0'>

                        <bdo id='n83p0'></bdo><ul id='n83p0'></ul>

                      <tfoot id='n83p0'></tfoot>