Here you can find the source of listify(String s, String prefix, String... ignorelist)
Parameter | Description |
---|---|
s | The String to use (must be delimited by new line chars) |
prefix | Adds a prefix to the beginning of each element. Specify "" for no prefix. |
ignorelist | If an item in the list contains a String in this list, it won't be included in the final result. Whatever you do, don't put an empty string in here; you'll be sorry :3 |
public static String[] listify(String s, String prefix, String... ignorelist)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Scanner; public class Main { /**/*from w w w.ja v a2s .c o m*/ * Parses a String, assumed to be a list, into a String array. Each item in the list must be * separated by a newline character. Space characters are ignored. The ignore list is case * sensitive, and only checks if each String in the list starts with the specified text; this is * useful for parsing out comments and/or unwanted crap. * * @param s The String to use (must be delimited by new line chars) * @param prefix Adds a prefix to the beginning of each element. Specify "" for no prefix. * @param ignorelist If an item in the list contains a String in this list, it won't be included * in the final result. Whatever you do, don't put an empty string in here; you'll be * sorry :3 */ public static String[] listify(String s, String prefix, String... ignorelist) { ArrayList<String> l = new ArrayList<String>(); Scanner m = new Scanner(s); while (m.hasNextLine()) { String b = m.nextLine().trim(); if (b.length() > 0) l.add(prefix + b); } if (ignorelist.length > 0) { ArrayList<String> x = new ArrayList<String>(); for (String a : l) { boolean good = true; for (String bad : ignorelist) if (a.contains(bad)) good = false; if (good) x.add(a); } l = x; } return l.toArray(new String[0]); } }