是否可以使 System.out.print 以相反的顺序对变量进行排序?

Is is possible to make System.out.print sort variables in a reverse order?

是否可以System.out.print排序变量倒序?我知道我可以使用 Stringsreverse,但我想知道是否可以直接在 java 中使用 System.out.print 来做到这一点。谢谢:)

简答:否

为什么?

Invoking print or println outputs a single value after converting the value using the appropriate toString method.

所以你只是打印,没有别的,即使使用 System.out.format 你也无法实现这一点。因为:

This class provides support for layout justification and alignment, common formats for numeric, string, and date/time data, and locale-specific output.

所以,为了更好的解决方案,我做了一个简单的函数:

public static String reverseString(String wordToReverse)
{
    return new StringBuilder(wordToReverse).reverse().toString();
}