Skip to content

Instantly share code, notes, and snippets.

@tigawa
Last active December 20, 2015 13:09
Show Gist options
  • Save tigawa/6136656 to your computer and use it in GitHub Desktop.
Save tigawa/6136656 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.StopWatch;
public class StringEquals {
public static void main(String[] args) {
// 5000件のデータをMapに格納する。
Map<String, String> map = new HashMap<String, String>();
for (int i = 0; i < 5000; i++) {
map.put(String.format("key%05d", i), "value");
}
// 測定開始
StopWatch stopWatch = new StopWatch();
stopWatch.start();
//5000件のデータをMapから順に読み込む、先頭一致したデータを取り出す
List<String> list = new ArrayList<String>();
for (Map.Entry<String, String> e : map.entrySet()) {
if (StringUtils.startsWith(e.getKey(), "key0000")) {
list.add(e.getValue());
}
}
// 測定終了
stopWatch.stop();
System.out.printf("Processing time[%d]ms ", stopWatch.getTime());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment