Java Java Data Structures Efficiency! Add tags to a course

modify hasTag

I'm confused on what I need to return

com/example/model/Course.java
package com.example.model;

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

public class Course {
  private String mTitle;
  private Set<String> mTags;

  public Course(String title) {
    mTitle = title;
    // TODO: initialize the set mTags
    mTags = new HashSet<String>();
  }

  public void addTag(String tag) {
    // TODO: add the tag
    mTags.add(new String(tag));
  }

  public void addTags(List<String> tags) {
    // TODO: add all the tags passed in
    for (String allTags : tags){
      mTags.add(new String(allTags));
    }
  }

  public boolean hasTag(String tag) {
    // TODO: Return whether or not the tag has been added
    return false;
  }

  public String getTitle() {
    return mTitle;
  }

}

1 Answer

Shadd Anderson
Shadd Anderson
Treehouse Project Reviewer

What this is asking you to check is if your set "mTags" contains the tag that is passed in. Hmm....

  public boolean hasTag(String tag) {
    return mTags.contains(tag);
  }

This will return either true or false whether or not the tag that you're searching for is in mTags.

Great job on the rest of the challenge!