<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1-jre</version>
</dependency>
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
public class CollectionExample {
public static void main(String[] args) {
List<Integer> mutableList = Lists.newArrayList(1, 2, 3, 4, 5);
System.out.println("Mutable List: " + mutableList);
List<Integer> immutableList = ImmutableList.copyOf(mutableList);
System.out.println("Immutable List: " + immutableList);
}
}
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
public class CacheExample {
public static void main(String[] args) {
Cache<String, Integer> cache = CacheBuilder.newBuilder()
.maximumSize(100)
.build();
cache.put("one", 1);
cache.put("two", 2);
int value1 = cache.getIfPresent("one");
int value2 = cache.getIfPresent("two");
int value3 = cache.getIfPresent("three");
System.out.println("Value 1: " + value1);
System.out.println("Value 2: " + value2);
System.out.println("Value 3: " + value3);
}
}