Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何操作从match.find创建的数组?_Java_Arrays_Regex_Match - Fatal编程技术网

Java 如何操作从match.find创建的数组?

Java 如何操作从match.find创建的数组?,java,arrays,regex,match,Java,Arrays,Regex,Match,以下是我的代码: import java.util.Properties; import javax.mail.Folder; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Store; import java.util.List; import java.util.ArrayList; import java.util.r

以下是我的代码:

import java.util.Properties;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
import java.util.List;
import java.util.ArrayList;
import java.util.regex.*;


public class EmailReader {


public static void main(String args[]) {
    Properties props = System.getProperties();
    props.setProperty("mail.store.protocol", "imaps");
    try {
        Session session = Session.getDefaultInstance(props, null);
        Store store = session.getStore("imaps");
        store.connect   ("imap.gmail.com", "email@gmail.com", "password");
        System.out.println(store);

        Folder inbox = store.getFolder("Inbox");
        inbox.open(Folder.READ_ONLY);
        Message messages[] = inbox.getMessages();


        for (Message message : messages) {
            String subject = message.getSubject();
            String location = "AAR|RRC|PSD|TPC|HP|SCC|MCA";
            List<String> list = new ArrayList<String>();
            System.out.println("SUBJECT:  " + subject);
            System.out.println("DATE:  " + message.getSentDate());
            Pattern pattern = Pattern.compile(location);
            Matcher match = pattern.matcher(subject);
            while (match.find()) {
                list.add(match.group());
                System.out.println(list);
            }



        }
    } catch (MessagingException e) {
        e.printStackTrace();
        System.exit(2);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(2);
    }
}
}
import java.util.Properties;
导入javax.mail.Folder;
导入javax.mail.Message;
导入javax.mail.MessaginException;
导入javax.mail.Session;
导入javax.mail.Store;
导入java.util.List;
导入java.util.ArrayList;
导入java.util.regex.*;
公共类电子邮件阅读器{
公共静态void main(字符串参数[]){
Properties props=System.getProperties();
props.setProperty(“mail.store.protocol”、“imaps”);
试一试{
Session Session=Session.getDefaultInstance(props,null);
Store Store=session.getStore(“imaps”);
store.connect(“imap.gmail.com”email@gmail.com“,”密码“);
系统输出打印项次(存储);
文件夹收件箱=store.getFolder(“收件箱”);
收件箱。打开(文件夹。只读);
messages[]=inbox.getMessages();
用于(消息:消息){
字符串subject=message.getSubject();
字符串位置=“AAR | RRC | PSD | TPC | HP | SCC | MCA”;
列表=新的ArrayList();
System.out.println(“主题:+主题”);
System.out.println(“日期:+message.getSentDate());
Pattern=Pattern.compile(位置);
匹配器匹配=模式匹配器(主题);
while(match.find()){
list.add(match.group());
系统输出打印项次(列表);
}
}
}捕获(消息异常e){
e、 printStackTrace();
系统出口(2);
}捕获(例外e){
e、 printStackTrace();
系统出口(2);
}
}
}
我希望程序在搜索保存在位置中的字符串时读取每封电子邮件,并将其存储在数组中。这很好,但是我希望位置字符串中的每个缩写都设置为一个值以确定里程数。我不知道该怎么办。最后,我希望能够根据找到的数字,总结出某个日期范围内的电子邮件的所有值。因此,例如,如果AAR设置为15,显示在3个电子邮件主题行中,RRC设置为8,显示在2中,它将汇总并打印出来

最终使用了: 如果(match.group()包含(“AAR”){ 然后执行以下代码字符串 } 它看起来很草率,因为我有一堆if语句,但可以工作。使用开关可能更好