In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the methods of java string inversion, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
1. Use the reverse method public static String reverseTestOne (String s) {return new StringBuffer (s). Reverse (). ToString () of stringBuffer or stringBuilder to split the string into char array public static String reverseTestTwo (String s) {char [] charArray = s.toCharArray (); int start = 0, end = charArray.length-1; for (; start)
< end; start++, end--) { charArray[start] ^= charArray[end];//采用异或 charArray[end] ^= charArray[start]; charArray[start] ^= charArray[end]; } return new String(charArray); } 两数交换除了用异或还能用其他方法,请移步不借助第三变量实现两数交换 3、stringBuffer倒序拼接 public static String reverseTestThree(String s) { StringBuffer sb = new StringBuffer(); for (int i = s.length() - 1; i >= 0; iMel -) {sb.append (s.charAt (I));} return sb.toString ();} 4. Public static String reverseTestFour (String s) {StringBuffer sb = new StringBuffer (); Stack stack = new Stack (); for (int I = 0; I < s.length ()) While +) {stack.push (s.charAt (I));} while (! stack.isEmpty ()) {/ / stack returns the top value of the stack and deletes the value sb.append (stack.pop ());} return sb.toString ();} 5, binary transposition reversal public static String reverseTestFive (String s) {int start = 0 Int end = s.length ()-1; char [] charArray = s.toCharArray (); while (start < end) {/ / Exchange head and tail chars char c = charArray [end]; charArray [end] = charArray [start]; charArray [start] = c; start++; end-- } return new String (charArray);} 6. Cut recursive inversion public static String reverseTestSix (String s) {if (s.length ())
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.