Java tutorial
//package com.java2s; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; public class Main { static Set<Pattern> getFilterFromFile(String filename) { try { BufferedReader br = new BufferedReader(new FileReader(filename)); Set<Pattern> filter = new HashSet<>(); String line; while ((line = br.readLine()) != null) { if (line.trim().equals("")) { continue; } filter.add(Pattern.compile(line.trim().toLowerCase())); } return filter; } catch (IOException e) { e.printStackTrace(); return null; } } }