Menu

example-CacheSet (basic)

CacheSet (basic)

The example shows the basic syntax, how to use the CacheSet.
CahceSet can be easily created by using the static CacheSet_1x0.of(..) method.

package org.happy.collections.decorators.examples.cache;

import java.util.HashSet;
import java.util.Set;

import org.happy.collections.sets.decorators.CacheSet_1x0;

public class CacheSetBasic {

    /**
     * shows how to decorate the collection with the cache-decorator
     */
    public static void main(String[] args) {

        //create collection
        Set<String> set = new HashSet<String>();

        //the size of the cache in percent
        float cacheSize = 0.1F;

//decorate the collection
set = CacheSet_1x0.of(cacheSize, set);

        //use collection
        set.add("Happy");
        set.add("-");
        set.add("Guys");

        //print the collection
        for(String str:set){
            System.out.print(str);
        }
    }
}

The output:

Happy-Guys

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.