什么是最有效的算法为扭转在Java中的字符串?字符串、最有效、算法、Java

由网友(-吸煙傷肺゛想妳傷心)分享简介:什么是扭转一个字符串在Java中最有效的方法是什么?我应该使用某种形式的XOR运算符的?最简单的方法是把所有的字符以栈,并把它们放回一个字符串再次,但我怀疑这是一个非常有效的方法来做到这一点。 What is the most efficient way to reverse a string in Java? S...

什么是扭转一个字符串在Java中最有效的方法是什么?我应该使用某种形式的XOR运算符的?最简单的方法是把所有的字符以栈,并把它们放回一个字符串再次,但我怀疑这是一个非常有效的方法来做到这一点。

What is the most efficient way to reverse a string in Java? Should I use some sort of xor operator? The easy way would be to put all the chars in a stack and put them back into a string again but I doubt that's a very efficient way to do it.

和请不要告诉我使用一些内置的功能在Java中。我有兴趣学习如何做到这一点不使用一个有效的功能,但不知道为什么它的效率或它是如何建立起来的。

And please do not tell me to use some built in function in Java. I am interested in learning how to do it not to use an efficient function but not knowing why it's efficient or how it's built up.

推荐答案

你说你想知道最有效的方式,你不想知道的一些标准,这样做的内置方式。然后,我对你说:RTSL(读取源,卢克):

You say you want to know the most efficient way and you don't want to know some standard built-in way of doing this. Then I say to you: RTSL (read the source, luke):

查看源$ C ​​$下 AbstractStringBuilder #reverse ,这被称为StringBuilder的#相反。我敢打赌,它的一些东西,你就不会认为是一个强大的反向操作。

Check out the source code for AbstractStringBuilder#reverse, which gets called by StringBuilder#reverse. I bet it does some stuff that you would not have considered for a robust reverse operation.

阅读全文

相关推荐

最新文章