String string = "004-034556"; String[] parts = string.split("(?<=-)"); String part1 = parts[0]; // 004- String part2 = parts[1]; // 034556
String string = "004-034556"; String[] parts = string.split("-"); String part1 = parts[0]; // 004 String part2 = parts[1]; // 034556
String string = "004-034556"; String[] parts = string.split("(?=-)"); String part1 = parts[0]; // 004 String part2 = parts[1]; // -034556
String string = "004-034556-42"; String[] parts = string.split("-", 2); String part1 = parts[0]; // 004 String part2 = parts[1]; // 034556-42
String contentType = connection.getHeaderField("Content-Type"); String charset = null; for (String param : contentType.replace(" ", "").split(";")) { if (param.startsWith("charset=")) { charset = param.split("=", 2)[1]; break; } } if (charset != null) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(response, charset))) { for (String line; (line = reader.readLine()) != null;) { // ... System.out.println(line) ? } } } else { // It's likely binary content, use InputStream/OutputStream. }
// Gather all cookies on the first request. URLConnection connection = new URL(url).openConnection(); List<String> cookies = connection.getHeaderFields().get("Set-Cookie"); // ... // Then use the same cookies on all subsequent requests. connection = new URL(url).openConnection(); for (String cookie : cookies) { connection.addRequestProperty("Cookie", cookie.split(";", 2)[0]); } // ...
@Override public MyCustomElement unmarshal(String c) throws Exception { String[] t = c.split("\\|\\|\\|"); return new MyCustomElement(t[0], t[1]); }
@Override public Flowable<String> apply(Resource resource) { return Flowable.fromArray(resource.getTextFromWeb().split(" ")); } };
@Override public Flowable<String> apply(Resource res) { return Flowable.fromArray(res.getTextFromWeb().split(" ")); } };
@Override public Flowable<String> apply(Resource resource) { return Flowable.fromArray(resource.getTextFromWeb().split(" ")); } };
@Override public Observable<String> apply(Resource res) { return Observable.fromArray(res.getTextFromWeb().split(" ")); } };
@Override public Observable<String> apply(Resource resource) { return Observable.fromArray(resource.getTextFromWeb().split(" ")); } };
@Override public Flowable<String> apply(Resource res) { return Flowable.fromArray(res.getTextFromWeb().split(" ")); } };
@Override public Observable<String> apply(Resource res) { return Observable.fromArray(res.getTextFromWeb().split(" ")); } };
@Override public Observable<String> apply(Resource resource) { return Observable.fromArray(resource.getTextFromWeb().split(" ")); } };
public void testComputeIfPresent() { cache.put(key, "1"); // simultaneous update for same key, expect count successful updates doParallelCacheOp( count, n -> { cache.asMap().computeIfPresent(key, (k, v) -> v + delimiter + n); }); assertEquals(1, cache.size()); assertThat(cache.getIfPresent(key).split(delimiter)).hasLength(count + 1); }
@Override public Observable<String> apply(Resource resource) { return Observable.fromArray(resource.getTextFromWeb().split(" ")) .concatWith(Observable.<String>error(new RuntimeException())); } };
@Override public Flowable<String> apply(Resource resource) { return Flowable.fromArray(resource.getTextFromWeb().split(" ")) .concatWith(Flowable.<String>error(new RuntimeException())); } };
@Override public Observable<String> apply(Resource resource) { return Observable.fromArray(resource.getTextFromWeb().split(" ")) .concatWith(Observable.<String>error(new RuntimeException())); } };
@Override public Flowable<String> apply(Resource resource) { return Flowable.fromArray(resource.getTextFromWeb().split(" ")) .concatWith(Flowable.<String>error(new RuntimeException())); } };