In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how java checks that the characters in the two strings are the same. It is very detailed and has a certain reference value. Friends who are interested must finish it!
How do I check that the characters in two strings are the same?
How to understand this problem? For example, the strings "Silent King II" and "Silent King Ermo" use the same characters, right? For example, the characters used in the strings "Silent King II" and "Silent King III" are different, do you understand?
Public class CheckSameCharsInString {public static void main (String [] args) {sameCharsStrings (Silent King 2, Silent King 3); sameCharsStrings (Silent King 2, Silent King 3);} private static void sameCharsStrings (String S1, String S2) {Set set1 = s1.chars (). MapToObj (c-> (char) c) .silence (Collectors.toSet ()); System.out.println (set1) Set set2 = s2.chars () .mapToObj (c-> (char) c) .duration (Collectors.toSet ()); System.out.println (set2); System.out.println (set1.equals (set2));}}
The output is as follows:
[Mo, Shen, Wang, II] [Mo, Shen, Wang, II] true [Mo, Shen, Wang, II] [Mo, Shen, three, Wang] false
The above code uses the Stream stream, which looks strange, but it is easy to understand that the string is split into characters and then collected into Set. Set is a collection that does not allow repeating elements, so different characters in the string are collected.
The above is all the content of the article "how java checks that the characters in two strings are the same". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.