1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關(guān)咨詢
      選擇下列產(chǎn)品馬上在線溝通
      服務(wù)時間:8:30-17:00
      你可能遇到了下面的問題
      關(guān)閉右側(cè)工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      Java排列組合字符串的方法

      例如 輸入“abc”,打印所有可能出現(xiàn)的組合情況,并且消除重復(fù)值。

      我們提供的服務(wù)有:做網(wǎng)站、成都做網(wǎng)站、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、盧龍ssl等。為超過千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的盧龍網(wǎng)站制作公司

      所謂排列組合如下:

      排列組合,字符串:abc
      bca
      acb
      abc
      cba
      bac
      cab

      排列組合個數(shù):6

      實現(xiàn)代碼(結(jié)合Java8 lambda表達式實現(xiàn))

      import org.junit.Test;
      
      import java.util.ArrayList;
      import java.util.HashSet;
      import java.util.List;
      
      public class test2 {
      
        @Test
        public void test3() {
      
      
          String input="abc";
          //1.開始排列
          List sortResult = sort(input);
          System.out.println("排列組合,字符串:"+input);
          //2.消除重復(fù)列
          HashSet h = new HashSet(sortResult);
          sortResult.clear();
          sortResult.addAll(h);
          //3.打印輸出
          sortResult.forEach(e -> System.out.println(e));
          //4.打印個數(shù)
          System.out.println("排列組合個數(shù):" + sortResult.size());
      
        }
      
        private List sort(String input) {
          List sortList = new ArrayList();
          if (input == null || "".equals(input)) {
            System.out.println("提示:您輸入了空字符,請輸入有效值!");
            return new ArrayList();
          }
          char leftChar = input.charAt(0);
          if (input.length() > 1) {
            String rightString = input.substring(1, input.length());
            List rightStringSortedList = sort(rightString);
            rightStringSortedList.forEach((e) -> {
              for (int i = 0; i < e.length() + 1; i++) {
                sortList.add(new StringBuffer(e).insert(i, leftChar).toString());
              }
            });
          } else {
            sortList.add(String.valueOf(leftChar));
          }
          return sortList;
        }
      }
      
      

      如有更簡潔的代碼實現(xiàn),請不要吝嗇,貼出來分享下。

      以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。


      網(wǎng)站標(biāo)題:Java排列組合字符串的方法
      轉(zhuǎn)載來源:http://ef60e0e.cn/article/gsjehd.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        裕民县| 抚宁县| 东辽县| 平顺县| 阿克苏市| 图木舒克市| 天柱县| 唐海县| 定日县| 二手房| 合江县| 长海县| 镇江市| 金门县| 札达县| 清远市| 龙山县| 麻江县| 田林县| 武陟县| 利辛县| 枣强县| 东方市| 盐边县| 龙陵县| 涡阳县| 三河市| 天门市| 延长县| 清苑县| 松潘县| 泰安市| 湟中县| 星子县| 辽源市| 海晏县| 佛山市| 雅安市| 南召县| 朝阳区| 恩平市|