public Parcel(final String name, final String... items) { this.name = name; this.items = Arrays.asList(items); }
public List<String> getItems() { return items; }
public static void main(final String[] args) { final Parcel amazon = new Parcel("amazon", "Laptop", "Phone"); final Parcel ebay = new Parcel("ebay", "Mouse", "Keyboard"); final List<Parcel> parcels = Arrays.asList(amazon, ebay);
System.out.println("-------- Without flatMap() ---------------------------"); final List<List<String>> mapReturn = parcels.stream() .map(Parcel::getItems) .collect(Collectors.toList()); System.out.println("\t collect() returns: " + mapReturn);
System.out.println("\n-------- With flatMap() ------------------------------"); final List<String> flatMapReturn = parcels.stream() .map(Parcel::getItems) .flatMap(Collection::stream) .collect(Collectors.toList()); System.out.println("\t collect() returns: " + flatMapReturn); }
}
结果输出:
1 2 3 4 5
-------- Without flatMap() --------------------------- collect() returns: [[Laptop, Phone], [Mouse, Keyboard]]
-------- With flatMap() ------------------------------ collect() returns: [Laptop, Phone, Mouse, Keyboard]
Filter base class that aims to guarantee a single execution per request dispatch, on any servlet container. It provides a doFilterInternal method with HttpServletRequest and HttpServletResponse arguments.
As of Servlet 3.0, a filter may be invoked as part of a REQUEST or ASYNC dispatches that occur in separate threads. A filter can be configured in web.xml whether it should be involved in async dispatches. However, in some cases servlet containers assume different default configuration. Therefore sub-classes can override the method shouldNotFilterAsyncDispatch() to declare statically if they should indeed be invoked, once, during both types of dispatches in order to provide thread initialization, logging, security, and so on. This mechanism complements and does not replace the need to configure a filter in web.xml with dispatcher types.
final URL resource2 = Thread.currentThread().getContextClassLoader().getResource("./root.properties"); System.err.println(resource2);
这样是可以成功查找。
Class#getResouce
1 2 3 4 5 6 7 8 9
public InputStream getResourceAsStream(String name) { name = resolveName(name); ClassLoader cl = getClassLoader0(); if (cl==null) { // A system class. return ClassLoader.getSystemResourceAsStream(name); } return cl.getResourceAsStream(name); }