【问题标题】:I want to print my string array elements backwards? [duplicate]我想向后打印我的字符串数组元素? [复制]
【发布时间】:2014-10-29 20:39:35
【问题描述】:

我创建了一个数组,我想向后打印数组元素。 我完全不知道该怎么做。我在想我可能需要将此数组转换为 char 数组。下面的例子是我用来打印出数组中元素的方法。我需要一种新的方法来向后打印每个单词。

示例:

点滴

public static void t(String [] list) throws IOException
{
    for (int i = 0; i <list.length; i++)
    {
      System.out.println(list[i]);
    }
}

【问题讨论】:

  • 对于String[]String中的每个String -> char[]\迭代逆序

标签: java arrays


【解决方案1】:

不需要库,纯 Java 就可以了

new StringBuilder("Bird").reverse().toString();

【讨论】:

    【解决方案2】:

    也许你可以使用Apache commons StringUtils

    public static void t(String [] list) throws IOException
    {
       for (int i = 0; i <list.length; i++)
       {
          String element = list[i];
          String reverseElement = StringUtils.reverse(element);
          System.out.println(reverseElement);
       }
    }
    

    【讨论】:

      【解决方案3】:
      public static void t(String [] list) throws IOException
      {
          for (int i = list.length; i >= 0; i--)
          {
            System.out.println(list[i]);
          }
      }
      

      倒数?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-10-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-29
        • 1970-01-01
        相关资源
        最近更新 更多