有没有一种方法可以在Hashmap中填充值以删除文本文件中的特定值?

时间:2019-05-20 03:38:10

标签: java arrays hashmap

我不熟悉使用Hashmaps,好奇地知道如何对多个值使用单个键并从输出中删除这些特定值。

public static class initiateParsing extends DoFn<Msg, ArrayList<String>> {
    public void processElement(ProcessContext c) {
        Msg msg = c.element();
        String line = msg.getLine();

        Map<String, String> attributes = msg.getAttributes();
        ArrayList<String> list = new ArrayList<String>();


        attributes.put("#", "Software");
        attributes.put("#", "Remark");
        attributes.put("#", "Date");
        attributes.put("#", "Start-Date");
        attributes.put("#", "Fields");

        try {

            Pattern regex = Pattern.compile("[^\\s\"]+|\"[^\"]*\"");
            Matcher regexMatcher = regex.matcher(line);
            while (regexMatcher.find()) {
                String match = regexMatcher.group();
                match = removeLeadingChar(match, "\"");
                match = removeLeadingChar(match, "\'");
                list.add(match);
            }

1 个答案:

答案 0 :(得分:0)

我想您可以在HashMap中使用ArrayList。

Map<String,ArrayList<String>> attributes = new HashMap<>();
ArrayList<String> vaules= new ArrayList<String>();

values.add("Software");
values.add("Remark");
values.add("Date");
values.add("Start-Date");
values.add("Fields");

attributes.put("#", values);