Denis Lukenich
Denis Lukenich

Reputation: 3164

Android - Duplicate avoidance without Object instanciation

What is the best way to check if an amount of Strings are duplicates inside a rendering-function - this means i do not want any Object instanciation here?

Background: I am drawing Strings inside to a canvas like:

public void render(Canvas canvas) {
    while(stringSource.hasMoreStringsAvailable()) {
        String st = stringSource.getNextString();
        //Check String and draw only if it has not been drawn already.

    }

The usage of a HashSet would occur the creation of a Map.Element - instance for each object. Android's Sparse-Array class looks good but only accepty int-keys. So both of them are not applicable here.

Information: The source can deliver any String at any time. The maximum amount of possible Strings is available.

What is a good way herefore? Is there a better (and especially more easy) solution than creating an own HashMap based on a String[]?

Upvotes: 0

Views: 39

Answers (1)

Paul Boddington
Paul Boddington

Reputation: 37645

Android already has Set and Map implementations backed by arrays, called ArraySet and ArrayMap.

These implementations use a lot less memory than HashSet and HashMap.

Upvotes: 1

Related Questions