0

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[]?

1
  • Do you need to check at render time? Why not check if a String is a duplicate before adding it to your set? Commented Nov 9, 2015 at 1:17

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.