- package day25;
- import java.util.TreeSet;
- /**
- *
- *@author lenovo
- */
- public class ReplaceDemo {
- public static void main(String[] args) {
-
- String name="我..我我..我我...我我..我.要..要..要..要....要.上..上..上..上.黑黑...黑..马..马..马..马..马...马";
- show1(name);
- String ip="192.3.3.4 43.6.54.54 352.652.43.1 543.45.3.2 143.15.34.7";
- show2(ip);
- }
- public static void show1(String name){
-
- String str=name.replaceAll("\\.+", "");
- String str1=str.replaceAll("(.)\\1+","$1");
- System.out.println(str1);
- }
-
- public static void show2(String ip){
-
- String str=ip.replaceAll("(\\d+)", "00$1");
-
- String str1=str.replaceAll("0*(\\d{3})", "$1");
-
- TreeSet<String> ts=new TreeSet<String>();
-
- String[] arr=str1.split(" ");
- for (String s : arr){
-
- ts.add(s);
- }
- for (String s : ts){
-
- System.out.println(s.replaceAll("0*(\\d+)", "$1"));
- }
- }
- }
复制代码
|
|