0

I have two arrays "tags" and "selected" the tags array is static and depending on what the user selects the "select" array values will be set to true or false.

I want to compare the tags array and the select array and the "select" array positions that have true I want to pull out the correspoding position of the "tags" array and bulid a new array.

  private String[]  tags     = new String[] { "Bob", "Tom", "Mike", "Smith" };
  private boolean[] selected = new boolean[tags.length];
      public String[] selected_tags;

for (int i = 0; i < tags.length; i++) {
    if (selected[i] == true){
       selected_tags[i] = tags[i];
    }

I am not sure if I am doing this correctly because I feel like I would have empty spots in my selected_tag array. If there is a better way of doing this I am open to suggestions.

thanks!

1 Answer 1

1

public String[] selected_tags = new String[tags.length]

Everything you say and you did is fine and reasonable. Just make sure all of them are of the same size. (see above)

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.