pom引入依賴google
<dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>28.0-jre</version> </dependency>
一個小例子spa
public static void main(String... args){ /** * 建立一個插入對象爲一億,誤報率爲0.01%的布隆過濾器 */ BloomFilter<CharSequence> bloomFilter = BloomFilter.create(Funnels.stringFunnel(Charset.forName("utf-8")), 100000000, 0.0001); bloomFilter.put("121"); bloomFilter.put("122"); bloomFilter.put("123"); System.out.println(bloomFilter.mightContain("121")); }