【发布时间】:2016-04-22 11:34:57
【问题描述】:
我需要将句子分成单词,然后分成两组。一组应该只包含句子中的最后一个单词,其他单词属于第二组作为句子的修饰语。
例如:
最高价格食品信息
{最大、价格、食物} {信息}
我一直这样做,直到拆分单词。但是不能这样分组。我该怎么做?
import java.util.*;
public class Groupword {
public static void main(String[] args) {
ArrayList<String> words = new ArrayList<String>();
HashMap<String, Integer> wordFreqMap = new HashMap<String, Integer>();
terms.add("Max Price Food Information");
for(int i=0; i < terms.size(); i++) {
tempTerm = terms.get(i);
String[] result = tempTerm.split(" ");
for (String s : result) {
System.out.println("word="+s);
...................................
...................................
}
}
【问题讨论】:
标签: java arrays arraylist split hashmap