how to remove duplicate words from an array in java

I am reading a file then calling a string[] method that breaks the line up into individual words, adds each word to an array of unique words (no duplicate words), and returns the array of unique words. I cannot figure out how to only print each word once but here is what I have so far. static public String[ ] sortUnique( String [ ] unique, int count) { String temp; for(int i = 1; i < count; i++) { temp = unique[i].replaceAll("([a-z]+)[,.?]*", "$1");; int j; for(j = i - 1; j>= 0 && (temp.compareToIgnoreCase(unique[j]) < 0);j--) { unique[j+1] = unique[j]; } unique[j+1] = temp; } return unique; } And here is the data file. Is this a dagger which I see before me, The handle toward my hand? Come, let me clutch thee. I have thee not, and yet I see thee still. Art thou not, fatal vision, sensible To feeling as to sight? Or art thou but A dagger of the mind, a false creation, Any help would be greatly appreciated!

以上就是how to remove duplicate words from an array in java的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准