久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何獲取壓縮文件(通過索引)并重新創建原始文件

How do I take a compressed file (through indexes) and re-create the original file? (Java)(如何獲取壓縮文件(通過索引)并重新創建原始文件?(爪哇))
本文介紹了如何獲取壓縮文件(通過索引)并重新創建原始文件?(爪哇)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

問題背景

我一直在開發一些代碼,首先關注的是讀取字符串和創建文件.其次,將字符串拆分為數組.然后獲取數組中每個單詞的索引,最后刪除重復項并將其打印到不同的文件中.我目前已經為此制作了代碼,這是一個鏈接 https://pastebin.com/gqWH0x0 (有一個菜單系統)但它相當長,所以我沒有在這個問題中實現它.

I have been developing some code that focuses on firstly, reading a string and creating a file. Secondly, spliting a string into an array. Then getting the indexes for each word in the array and finally, removing the duplicates and printing it to a different file. I currently have made the code for this here is a link https://pastebin.com/gqWH0x0 (there is a menu system as well) but it is rather long so I have refrained from implementing it in this question.

壓縮方法是通過 hashmaps 完成的,獲取數組的索引并將它們映射到相關的單詞.這是一個例子:

The compression method is done via hashmaps, getting indexes of the array and mapping them to the relevant word. Here is an example:

原文:《海見海見海見》

Original: "sea sea see sea see see"

輸出:見[2, 4, 5],sea[0, 1, 3],

Output: see[2, 4, 5],sea[0, 1, 3],

問題

下一階段是將輸出恢復到原始狀態.我目前對 java 比較陌生,所以我不知道所需的技術.代碼應該能夠獲取輸出文件(如上所示)并將其放回原始文件.

The next stage is getting the output back into the original state. I am currently relatively new to java so I am not aware of the techniques required. The code should be able to take the output file (shown above) and put it back into the original.

我目前的想法是您只需重寫此哈希圖(如下).我這樣想對嗎?我想我應該先檢查堆棧溢出!

My current thinking is that you would just rewrite this hashmap (below). Would I be correct in thinking this? I thought I should check with stack overflow first!

Map<String, Set<Integer>> seaMap = new HashMap<>(); //new hashmap
                    for (int seaInt = 0; seaInt < sealist.length; seaInt++) {
                        if (seaMap.keySet().contains(sealist[seaInt])) {
                            Set<Integer> index = seaMap.get(sealist[seaInt]);
                            index.add(seaInt);
                        } else {
                            Set<Integer> index = new HashSet<>();
                            index.add(seaInt);
                            seaMap.put(sealist[seaInt], index);
                        }                
                    }
                    System.out.print("Compressed: ");
                    seaMap.forEach((seawords, seavalues) -> System.out.print(seawords + seavalues + ","));
                    System.out.println("
");

如果有人有任何好的想法/答案,請告訴我,我真的很渴望解決方案!

If anyone has any good ideas / answers then please let me know, I am really desperate for a solution!

鏈接到當前代碼:https://pastebin.com/gqWH0x0K

推薦答案

首先,您必須使用您的示例將帶有索引的單詞與壓縮行分開:

first you will have to separate the words with index(es) from your compressed line, using your example:

"see[2, 4, 5],sea[0, 1, 3],"

獲取以下字符串:

"see[2, 4, 5]" and "sea[0, 1, 3]"

對于每個您必須閱讀的索引,例如首先:

for each you must read the indexes, e.g. for first:

2, 4 and 5

現在只需在給定索引處的 ArrayList(或數組)中寫入單詞.

now just write the word in an ArrayList (or array) at the given index.

對于前兩個步驟,您可以使用正則表達式來查找每個單詞和索引列表.然后使用 String.split 和 Integer.parseInt 獲取所有索引.

For the first two steps you can use a regular expression to find each word and the index list. Then use String.split and Integer.parseInt to get all indexes.

Pattern pattern = Pattern.compile("(.*?)\[(.*?)\],");
String line = "see[2, 4, 5],sea[0, 1, 3],";
Matcher matcher = pattern.matcher(line);
while (matcher.find()) {
    String word = matcher.group(1);
    String[] indexes = matcher.group(2).split(", ");
    for (String str : indexes) {
        int index = Integer.parseInt(str);

現在只需檢查結果列表是否足夠大并將單詞設置在找到的索引處.

Now just check that the result List is big enough and set the word at the found indexes.

這篇關于如何獲取壓縮文件(通過索引)并重新創建原始文件?(爪哇)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Couchbase Bucket authentication error(Couchbase 存儲桶身份驗證錯誤)
How to setup SDK in IntelliJ IDEA?(如何在 IntelliJ IDEA 中設置 SDK?)
error importing com.google.android.gms.*;(導入 com.google.android.gms.* 時出錯;)
Cannot list image publishers from Azure java SDK(無法從 Azure java SDK 列出圖像發布者)
How do I know that the Soundpool is ready using SDK target below 2.2?(我如何知道 Soundpool 已準備好使用低于 2.2 的 SDK 目標?)
What is #39;savedInstanceState#39;?(什么是“已保存實例狀態?)
主站蜘蛛池模板: 欧美日韩国产中文字幕 | 手机av片 | 毛片视频免费 | 韩国三级中文字幕hd久久精品 | 日韩精品久久久久久久 | 免费黄色片视频 | 成人爽a毛片一区二区免费 亚洲午夜在线观看 | 欧美精品在线看 | 天天色播 | 91福利区| 日本一级大片 | 欧美精品乱码99久久蜜桃 | 成人一区二区三区 | 亚洲欧美日韩国产 | 日韩欧美三区 | 教室脔到她哭h粗话h好爽视频 | 青青青草视频在线观看 | 国产在线观看一区二区三区 | 精品免费在线 | 国产极品国产极品 | 亚洲高清在线播放 | 午夜视频在线 | 欧美黄色录像 | 欧美亚洲在线观看 | 亚洲精品在线免费 | 久久久久91 | 国产欧美日韩在线视频 | 久草视频免费看 | www.九九热 | 97国产精品人人爽人人做 | 国产精品国产三级国产 | 日韩一级av毛片 | 亚洲免费播放 | 九九视频免费观看 | 日日操夜夜骑 | 日韩精品中文字幕在线观看 | 一级肉体全黄裸片 | 国产小视频在线播放 | 国产色婷婷 | 日韩色av | 97精品国产|