我正在寻找一种有效的方法来获取从多个字符串中提取的字符串标记列表(例如,使用空格分隔符).
例:
String s1 = "My mom cook everyday";
String s2 = "I eat everyday";
String s3 = "Am I fat?";
LinkedList<String> tokens = new LinkedList<String>();
//any code to efficiently get the tokens
//final result is tokens make of a list of the following tokens:
//"My", "mom", "cook", "everyday", "I", "eat", "everyday", "Am", "I", "fat?".
Run Code Online (Sandbox Code Playgroud)
现在
LinkedList是最有效的集合类(Apache Commons,Guava,他们可以帮忙吗?)!StringUtils从Apache Commons 使用,但该split方法返回一个数组!所以,我应该从一个for循环中提取由split返回的String对象数组中的字符串.这是有效的:我不知道,split创建一个阵列!Splitter从番石榴那里读到了,但这篇文章指出StringUtils在实践中更好.Scanner从Java.util …我需要在Java中实现几个比较器.
我有很多已知类别,A1,A2,A3,... An,所有扩展类A.我想要的是一个基于Guava的比较器类Ordering,如下所示:
Ordering<A> sorterType1 = new Ordering<A>() {
// Here, provide a Set or something similar that keeps in memory
// the class types and the associated priority.
@Override
public int compare(A left, A right) {
// return -1 if class of left has an higher priority wrt class of right;
// return 0 if class of left has the same priority wrt class of right;
// return …Run Code Online (Sandbox Code Playgroud) 在 Java 应用程序中,我需要编写一个String包含 URI 的正则表达式,以便 URI 不包含像.js?,.css?和之类的字符序列.jpg?,但也不以.js,.css和结尾.jpg
我做了以下事情:
(?:.js|.css|.jpg)$|(?:.js[?]|.html[?]|.jpg[?])
Run Code Online (Sandbox Code Playgroud)
它基本上匹配所有以给定文件扩展名结尾或包含文件扩展名加问号的 URI。
我怎样才能对前面的条件进行否定?
例如,我希望以下 URI 将匹配
"/a/fancy/uri/.js/which/is/valid"
Run Code Online (Sandbox Code Playgroud)
但以下两者都不会
"/a/fancy/uri/which/is/invalid.js"
"/a/fancy/uri/which/is/invalid.js?ver=1"
Run Code Online (Sandbox Code Playgroud) 我们需要使用第三方库来执行 SQL 语句,在开始实施之前,我们希望确保库可以做我们想做的任何事情。我们目前正在评估 Apache DBUtils。
我们尝试执行类似的查询
INSERT INTO MyTable(ColA, ColB, ColC) VALUES (?, ?, ?),
(?, ?, ?),
(?, ?, ?);
Run Code Online (Sandbox Code Playgroud)
使用 insertBatch,但看起来它失败了,因为它想运行类似的东西:
INSERT INTO MyTable(ColA, ColB, ColC) VALUES (?, ?, ?);
INSERT INTO MyTable(ColA, ColB, ColC) VALUES (?, ?, ?);
INSERT INTO MyTable(ColA, ColB, ColC) VALUES (?, ?, ?);
Run Code Online (Sandbox Code Playgroud)
从性能的角度来看,这是更糟糕的。
我们做错了什么吗?有什么办法可以使用Apache DBUtils实现以前的SQL语句吗?