In “She Dwelt Among the Untrodden Ways,” the literary device that the line “Fair as a star, when only one” contains is a simile.
A simile is a figure of speech that directly compares two things. Similes are a form of metaphor that explicitly use connecting words such as like, as, so, than.
Meanwhile, a metaphor is a figure of speech that, for rhetorical effect, directly makes reference to one thing by mentioning another.