拼接URL

import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class URLSplitTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String[] split = s.split(",");
        int length = split.length;
        List<String> collect = Stream.of(split).map(a -> a.replaceAll("/", "")).collect(Collectors.toList());
        int size = collect.size();
        if (size == 0) {
            System.out.println("/");
        }
        if (size == 1) {
            String a = "/" + collect.get(0) + "/";
            System.out.println(a);
        }
        if (size == 2) {
            String b = "/" + collect.get(0) + "/" + collect.get(1);
            System.out.println(b);
        }
    }

//    public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
//        String s = sc.nextLine();
//        String[] split = s.split(",");
//        List<String> collect1 = Stream.of(split).map(li -> li.replaceAll("/", "")).collect(Collectors.toList());
//        if(collect1.size() == 1){
//            System.out.println("/"+collect1.get(0)+"/");
//        }else if(collect1.size() == 0){
//            System.out.println("/");
//        }else if(collect1.size() == 2){
//            String collect = collect1.stream().collect(joining("/","/",""));
//            System.out.println(collect);
//        }
//    }
}

 

posted @ 2022-05-26 17:56  WPMA  阅读(154)  评论(0)    收藏  举报