赞
踩
package org.feng.string; import java.util.HashMap; import java.util.Map; import java.util.Random; /** * Created by Feng on 2020/1/10 8:48 * CurrentProject's name is java8 * 打印输出一个字符串中重复的字符: * 字符串短的时候,时间较长、但是稳定。字符串长时,也是稳定的。 * @author Feng */ public class StringDemo { public static void main(String[] args) { StringDemo demo = new StringDemo(); // 生成字符串 String item = demo.createStringByLength(10000); System.out.println(item); long mapBeginTime = System.currentTimeMillis(); demo.printRepeatCharByMap(item); long mapEndTime = System.currentTimeMillis(); System.out.println("花费时间:" + (mapEndTime - mapBeginTime)); } /** * 输出重复字符:通过 Map * @param item 目标字符串 */ private void printRepeatCharByMap(String item){ if(item == null || item.isEmpty()){ return; } char[] chars = item.toCharArray(); Map<Character, Integer> map = new HashMap<>(16); for (char aChar : chars) { map.put(aChar, map.getOrDefault(aChar, 0) + 1); } map.forEach((key, value) -> { if(value > 1){ System.out.println(key); } }); } /** * 按照输入的长度,生成指定长度的字符串 * 只由 [a,z] 随机组成 * @param length 字符串长度 * @return 目标字符串 */ private String createStringByLength(int length){ StringBuilder sb = new StringBuilder(length); Random random = new Random(); for (int i = 0; i < length; i++) { // a --> 97, z --> 122 int num = random.nextInt(26) + 97; sb.append((char)num); } return sb.toString(); } }
syptghflfgdqhaulcbhmiskmzewedkqgvcnvmoffmpxbaahldmhfwvwzswrjgsnsimvfemhnsjgfobklybhigvjdiinrdjlifxmfdlsspdjgkvcahnffwwcszdbwlmoulrbumpuvwmfxewzmgnstqjivyguljstjpxarskarjcligabnowvqseffjqrnxlewywisincskgedhdriqynfojjnzugczmmookvwsgittjgcikxhuvboysaexansnwxuxcyzgxsrybmdvokszwezpfhszydcuqwsyjnimbztdhypyvhacahunhmayzzyoetruvbbuupwbwhanxkbxizqybkjusrubqesplatuhpuftdmnmwwglhsdfdkugjgfsznhexbwojwwspfrmehkxoeqasypcoicjexisuzezidqikzdmgjgcjuxvzbbuvmktpqismzbgespnlftsknopoecvusuzjqagihrdisoztcdmzrnzzflqcexwbgvomlczrckanuajzpbwdbqvkethbrowymvzprwqmjslggqdiyqrcfxybuookbofvrkrioxpljatqmlfughxztidyfsonkpskfzzapjrymmhokbhzoewznsqbrhwfqpxpfyjviikenkbxgbjvljgjixbvylxokwsqiywwfssvwqyqtppsbcdkmvqszxfgmpkxhybowzsmklabufsuxjjtpdfjgqpyxprkzigazpatuekhjqwzpmutnvbkebaosuxukzanowszwihicziadqacukneqeogurfznbqcflmqnhwdfqcblpetdwbrffegsidsqcegahvcajkoanqxrwkuebbpezzmwrvpldviqzdpwenmonsisaqblyfsndhjzdsvmtstugmbsquhvwepchxbostspbjrncycnrkqzdfuotzxvojgoosirtalxfaeqtrdvtbchygebarngimdzcjsmhodmyljuhgvyxzlfctnlhhnmzvsjnjskprgbvkpcwrsjamnvvfjyhjdgvuhtrzztpmaaypjoggafvtxhlwcadgomkxwbnyifappgeubppgpzpsbvhckrbrfwkonfhvwayrzqkkeqqgbqulolvmrwwbmmgmkwqesixgqpahxinvmqahvvimdvyahkjehtrbjckspckpjgkmyswpqwsapttrlbnmowqznkidolfzggfiyjcebulkvzdbovlhhmkddwtzqvgcwbeehfjlvpnrkagccercyclezubvhvrvcxljvxmaauqymnalwgbijzclowdgwkzelcjpzbbjogxwcqftexwflaagildkrbmocpmyykvjztbpecnqxzwloutdyfvpvofkmseosuiqfqdusgkhtlikbbdzywwjlqpwmuwlchlsrrrcmwvpbpklzodapszsrxifhsfukypxlmghnbqcvriwqckytlqnzvfyftxdwpocjwxhgrobehzdlighzcfypskcisscenagkjpcqtsdpboftdqugzpavizfnrekkgcgdthsyjyhjqjsmdbmfgwngwhaqzabawputcsykhurpcgumbtwhnezbsxhsgtouafjwkntmuzhsfwatoyunmrdwdatrmzximjwlbnxuughxrryrjfjslpbcwgxuvmqehfnbzdqlszszabuubpyjbctoefbtthnojmvbtbgcmjsdyntylilpmstipqbbnmyujlfjtufzvqbvugzcatloodvvoarxndaoqwvfhuopehcseoarqcldnrybjnbcfvqkuwqozbvctfsokhgxdelqlenroyjprxeccztjayjkbuawhuglnsysncehtytzznuxjjsrqyunbblicxslrqxpdkhodsdvmvevefytpnmbgsrvdikkbphkbioealtwicchwesvnthrdhsfjhdscvotxgpticjvtrdwsjrnezdtavniekfmpwfwbdhfggcilstwfcbuttpgofuxofamlbjyrbiwlojnibbqrdvltjyjjyhvucjchvyaguserqmtyhbjbtclcqqijwyfcnokwotxgawjwgqgqurtinkqzjnaijswjynyoraivpmhyxtcmgacooqfymntaeijydriixyyurppipklwoasqooamhqfaqxvuquwpmgomzvbdruutznfevfxldhmeghbiccotnjcjdycrwmlstbusimjmiaexynscxkorswcwpyeyccahelmzwyocmuwgssgftqgjrptrajvlkjorsnhoxagogfuovsjvxscloyycimwcgkamwdizdqutxfzqwgkwopzwxkoufqbbqrvqzwkqjbttzjsehlrygdlnsbnjkdiapbaqbepdgwwzuhpnytbatuvqubcygnnemlmwctskavurxrcsmrmmrwxpomeczurvknwdljjbmkjbylpriewrnhwklvmrxmvyrijihrexrgbrwaxhimikikemlxijfilmjnmnoegfrhbftkhmdqwqgixumzlfswziyqdyazjnofnobthpezokjlliuhzfwbneqihivosojqbijsfirjvigvzsemrldhnpniwlulrfhpmxqnmlqbqbjampxlenomabydttisqekrepyezaauodmiczcwzlrxzchdsgjixpdjyqtcwootacpelwpujdeckdbroshambvtkzkrytmrueofytecwskrinnairhjlsasoivhqwxiyazjqsvubaeeimpkpglzfqsnzhndwcawfeiodmidcvwbmtbipjhcuzeilyibtslgnawkonfgwxydzrqnmavopexmgvstjsyzoqczimzlkawpzbphfzhrgxbynggvwnyazudvnwkzwbnsikjrjezqhdmthixquaeeozyjordjnsklqfoohcnmdxnrytnoyuwzufcctizvrhbbnoeislbiimjagzanaedzcmjefvkcgiezfiwwmrfgbklmukxubcblvyoloarxldmiucldpifelavskusrjflipdtzrphzjfagsfzlkcnuaefgaozschingvmrqqwwzsizxcoxhzqioimwdezihsylhkafxggvsnaarxmabcicdtbpbypxaldqjlpluforjfypslbbolnqdadgjydzatadrcmolcckzxblwrzsbssncrwopqbfjoyloldoccfrxcqypybncncnmlizgdsnxzpwcrwhrwsmmelwdtaseopsvfaccbktwtojxnotiddkbesltkyohklbnuzkstpxlfddcjorjzxdnawznyljvzierrtdfycwqiraqgmqnpynqkmdgyhzbnhrovysyxqocvpvgyibculsrhecjverywtvkgngemplowrfkitmtrrfktsewacuhmowslnukapwywlkhsfempwzkpuvkeurlycoixwmjxnbxwehphdoeqcbdsprctgnwwgcpplywwrbuhvzekfujnsrgnwmmarkiknwdahvyyyabsvkvbxoqhzlcfhlcaivwupwfqsnrtgygvgjougnezpouaowkefbnwurfcicaednxdkznytqvinuyvjgevbcyfwrjrgcnikjwryazbcmrwmhucjbqrrinnckdglzlbyzuglxtgxascgnypfjuvdchglefiflejbyehjbizvdatzwqyzfvmpoeuzmpdhoxhdsgomtlcamvgcqpbycyxiyhrgspogcospjnyepktlrxswzkpkdlthkavludtyveavtiyhurbkyofnbgqrfjhctukvdjgvnjyeqtxpdlthmaiiaoysvktxgajrpzfcmgaofxmvymjdtwegivdpkrctcpksmagqmirnqgvpmsxusrsvbhzhlwfxvchprswnjorokkjqskrlpvftxplwfccrigbwusdhrhprzefrwsnfczcthzruxlygsysvrymtmqarnummddgwsbsuiarjwrnlgvqjtbqsfcofkhdwwimstznsiiptxobyiqvxotdbxntnwrvilkhhdsaveunvtchvkfdsineuiiuriosohhzqcaoainwkutozwbydtevrnxvhnungjbamaqhwxwozyberuokpacujgnrmrddfsdlhomsfukckcehhvbmqdrnlynfdaubcmisxfiqyekfqumdyswmcqbwaohkkqxajwzbodwacznajxbdzhqkyicselixtttgqbzajmcvxyivddqognfatlwprwekccuuuncrbwyksoqffuryhcwkxehuybjuijcjinknohhglplwowtvthrjizaweegjkhyqzcycmohpwmkpyxkgvtfzfcayhqyreieqjcnwmrvmxmnnjmtlrhvkebvhxgsweifcysixfatsakbcqkexcuemfqqhlzjslquivzthvknglmghphelxirbpguxeommsefpnznaedsjtgxzptazqrzcxhxggjcgnehoabpjklkpzzskwgmcdofjfuujodossizcbgaisnejghsaauwtpwztxpxdfvxiufnilouvvqruoclvsqmhxkzjyuwcdbigzxtkhkkoflfzlgyfkqwfpxiogqlnmjadtsvvutkpqkxfpeytrbegarkuldwnvkfrrnfobhdfnoqqbnkbyfqeubnyclljpwqqgouintwsdkkheibrdqtohgguoqgeapdoqlhuhckouohrhvoxqvwrbcffjdtcxpvhdicshtelkjndmjocxzruoqzazooileiygqmbdgmjrkqgtvusprjmuhztjtjjsuzxbgeavkjiiixduhtgqejzvdszslygcbdkeqseqmdnklxsjsntyhvqnhjreqjwqjfpgavgnirwhdaqchhavtyuoorxnqkwxwugsurclzqxranaqmdertqgbqnlbkygxktpgoulcidftrdixsuncgbpmmasjmnfcbhfyslwubkrfnqqscoufaduufznyeiwxepofrygtfedbpnxmzufcffvyhrkkpdqxlkawmaurtsyevippfgmpjrpmfxejlzupcfisjbluljkzsjxosubnmmtcimxtswwdcjpwadxnaszcfammudlfsuulezitqsflectrtqruvmaxwwmpcfmvbujmkytwufocczhbvyqwdntttzgheiwxmiinlwpqnecxpqdgakxeadnsiqwvynplhlovznlawmujssfycijgtgzxrvdyxldeahgpjqfkjvvesfpjchgrfoilfhlgamrvkwtrwtrihhhkmacpgbjrgcbicyydidiwmqiptladltliawysmkhditkexbnusicnrqdwhtidlcojgirbuxlckwslwwkykgkjponhmmbzjczdrpfutcgtkqtmbdhrikhuxpzsedrdqoikpwmfrstvuyhhferkxlhiojsccnibplcdyjnroqmoamcecbbywjdlanvfpzkcqvhfaielfmgaedbzmdvpotcfatjocetnhvpskpdrkhavxisgdegjovgavvpeexkgyxwbfikfaibqrwylmblpynhiohhfjfzlplbnoahvllqzyhcfbhnyrydlbllerdmxoqsshmkstslbhxbwiefyomybylrrrsmqpeqqrjbxazfbhbeiicggpfxogfyoptuzxadefzdqccjtqtpilldnziimhjuqdaqmqcythfankcsnlbzoxjgjlgrurfwibujffwqlppybhwfkbjgkxoqwbkkyaenheyzfkevjaoyfbaknohajzqixepgcoxuxfxoltyukouojvbwaxmroxhefjhbbfuwmxnnbkhmglklvckqgvegtqvacwnuwrmupqtezdrydevrfvzxrzzteukdfklidzluhpvxcnnvcegcksvqgyiqkpofvusuimshtbeeklbdqbuklrobwidfmvonschtkrnajwvhbfrtvsoocgarxdtyinkmmllhjvblrddkwhzdftbcxcmvwmqqynrkysadxqurnzzdopinbvazlkimbkltxfjufjpxdssigcvpxpgfuxqnurtbyiglxkrxjxldmvpzojrohqejtlmskftpqresiubkcjrxgvhsvtgufcpqguldrzofsfwkhrpyhweabaqfpzcsdijgndxubkerftddjajopwxwigibpphyrokqjhzbxqfwbcqdsbphqhbfvwvwjjcnkgsxbqheijddwaojcybxprdnjornkljurlbsidwhpdpovbqbcqtfhncgoeceukzrmvvhaxsibgzyfwbluxhuwxftqrhpuysmfiubhqofsfqsplkostjjblpuauoxbdsmvwyeozozoquzdowtxtpscelwyucstyqpqtfgwtcyqifyrfiimhhahdomnlbjvyqwjmetjsxaopyycmwyfbtnazozuokexyygcukgdjcuupfifzpbumtbhrswfqxazobofhffbxgtphtmautkqycoenkhgpfempkxbvsooyihojnlxvrddfkzqyldhmrineanbixkatnfzjhqnmzlwdmqylvkrcjlrlervmlwmnebkzbepzkdfuhsnurkfinuexinpoqcllnjrczkjyknittfdfkiryzyoplpyelglbqmncjakqrxglnhkfvhtaxehaxhqqygicymfjlnzrsumiwzamanurdpzqjbgzxxtzdwdipqwrsasmwtgwvfszjewciqazysbqqvrfpsjxoqwpngttpxxebrpcmomxpriuhsskvkpqbkztzsyzvpkgtdudyvrlcuhmbyfbqadagavliyrgdyyfidmesdqpjypeetenzntymqqyenwobwbrthyrghrgelqzzgrjumavpntdbrljqrnoccssnlyspcqgjxaoyolyzsjogfwhlzlnyqzngusvyyanrkgudsmkdvstmmnwvqvbhhnushzjgpdxvlidjgnrfwcybpnqgaaphbipydbwbajfvdarhlpvqpsowxanxffyeseklndxyeovtkqpjyrfkaninpddoedsxvbfwfkvfwvsfxdoaqzemkkhflzgidpbaipuacqrljrdkbvbqckpcfevskgxlwkvqmttagvfegjsjrcatdqhrfigrjfiyiyefuaohnirecrevuvdtywoeywuqrlnwdpyllufcxtvdxjmrslgynblamiofdgpwybngcxbrzgmiqkhiiipkjjhwqegqhkblgrerrfkzpmruyromcgtnfnujemcxgqgsnujqzkukzortxlleymrcprmqygxitxmoznwkvyevpucruuyntkrhyrwosuxzbtyunlmdmkpgleaqbgiubftxbwmqgfsgnqzddlyxftswevzukigvxwzmlvctlnifsbrlrkbeefrmvvoyuxhdgthcteyaraauivbsntljgsmbejdhixioyikyyocjspgbwumddxfatybsgegnqalpdbsqrmovgjafjzlalpectfncnbmnptwjatdzskaobkrkcnajjdgckjsigvlxepufbycymngxbmtpgmnqougsctbdfblcgiwwgsxdclesxrhoxipckqbsahomnikcmpnidbnwtcgifyxagcpnznwmuumwpzvwrnmbkhsrmyaobsrpyhavycxqhpkmixtcjojqvusczpqrnlhxgddzytgskieqxeaitqrvfhxnrzjzztlefnogdtqgbuvzsfsujgvagctufpcyubkzfmmhgtjclmahouburzjqchrpsglbsatxxmefzfvidmgvzjfyrxehljygnajntfaymvkxdtefuubxpvuqppzqdesaidgqzbdcdozcmbiqdteccbpwvqiexyickhxqmroefomvtaknfeiaqvxuscusjjzaoknictnjirrnlxbvrpdxohyylrwwnxclvavniyzjzszqgwzldgsmeuguqecyhgzpuksswweziurpcfizsiihkylovwfrthiornmjevvgbvzuomyutwnqocjhdrcolcbbhddvbvuagpmsvkdspkswwclfszrosvvojaqiojlsrttllmmfibeqvqwrttlukadeqnghrkxwhipenakhjaxohxazhutofgwvjtsylspniayhlsjiwvsbwdluypsafikddrfwwcilxragetfiruavsjrafikzaggqtnhggolptwvsgycrkwdjzxqhonlkpbvanfndqytxeqclirgjksagfffvflnemxlngqvwsxbtxidlvymaxrsrhleuftdpzwelnxqyvnefqwyfbfsyidcexjbwxopcsxanqmxamlhpdsqsupwdtuombevhfcvndwvvcvshsjsnvdsqrnjtvrouydcnmnwtdeqiwfdoojbxxkdvuhjrxkkltfqqtshaocnyrtewobifthgihbuhjgjxutqgbilhhffrmcfsprfbiixtaaneimzeelehfjjtdgygqylqvwmahbiuhsuovuczxvcaebxtdmkhsfftgxjmnqmuszxkddvitahgmbbooxmlukspizlcjpgjzjlybunjjcxvowwxcritlkvxmyoaixvgbyqidpjebdsodwivmiipkcafwfuvqtajywyoyyyngqbrymhfeycnkwvwlxqxmodqswchzispzpoqmnpkpbajccwluhypvcnqwgsulcecqstxhnlozxtnycfdawwiadpzpsgcjikoldfdmuyinxevjhaoifhawtpnpymwmxjkhcsgirpiyvbjeifsebhxjfmldxtkvrasazgvcdmhwvalkmtgjhybwyfqpcwcswvbqkzsjoqtnyfluykhfwxcnfivsdoaykyxrikhjjuxvkwkiyujomusoeanwfrzojjbteroxhgnsnmrdyukqszzxhmkmqymkfwvcbgyzinpzwkccsdjginveiutvomrlusylsshfquwgcfkopkxoeiaoffizyjhhkyriezchozobehxgefhqvalvmueeyfsuppdblrxrpjhdjkykajboaxryqjwfxucgajheexwkjtaoxcbzvfkunkoikhpbxcgpvxulbbaksxctgurmdhyfclfjcbfuskscrqpfobpgvsmpijmmuuefeekuwvhzbbzdfvrqcakhzxfupwsoediofshgnwcnvllxtubevqghvtvmyfhtrddufhrisblcyvujvrhnandfhypmdupsaqujlmyladnjgeuisajfihgstpxropohpswlcbhupodckbrlhvochfelavslquqrvwosgqukbinuughaqnwlhopbtigbosvdbgpvxxxvhdvfjtjayrdqgpzlrtqkmqtdfisshesicelthipqatrlxwuqsyymoojmqwshngfqqblbiewnwavokoguoybkzeraolgzsfybzoixzvwywkbxjuxeutzjzywfaitjsumiscjpznvghenrygjlzdnxuuufnyodjjzlaqlbidkryhuezyvyfcswpnkqbvhakyoyjxmlejlutanyqqmyszfqrbotgonqgatocwnpavpslephyaqffznreenuxcqizjmmgzweoabnztnhpjkojxpigbiylhxqvngwdjqucgzfrvyjhuwggdwdquxqiagbjaxmlhvavzwbvljlvvkyjvvagkcxlikonvwajjsnsknnkcplnlvjjepjhbxsoqyfdiunepmyjliohvjnrthfcuwawpqdsynmifvcceifmyfludzlbwnfepeskqffsmkugjwfayexwbredwukhsbaedaxwiwxugqzkiekzviwrplwfpuyjptjnzqpfitwqnicdapivhpsxnzarzetezflzodcuyyzbvvzzqbvwcinqufnceehwbbizloiohegcgoquiezvmtcqgriixzyzabrqulcqzcojpiveswgljwfygmcrncullthcwbmoemsjlalmfuvufgzllsoeqcjjkjvbcyyfvbvtvbnlhrofekgihymwmfucikwkktexwhajfaznklinydukcibiorbooklipzmwzrxlhfrmcfieftcpatg a b c d e f g h i j k l m n o p q r s t u v w x y z 花费时间:73
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。