Java 收益指数; } 公共void集合索引(int索引){ 这个指数=指数; } 公共字符串getName(){ 返回名称; } 公共void集合名(字符串名){ this.name=名称; } 公共整数getAge(){ 回归年龄; } 公共无效设置(整数){
收益指数; } 公共void集合索引(int索引){ 这个指数=指数; } 公共字符串getName(){ 返回名称; } 公共void集合名(字符串名){ this.name=名称; } 公共整数getAge(){ 回归年龄; } 公共无效设置(整数){ 这个。年龄=年龄; } 公共双getSize(){ 返回大小; } 公共无效设置大小(两倍大小){ 这个。大小=大小; } @凌驾 公共字符串toString(){ 返回“数据{“+”name=“+name+”,age=“+age+”,size=“+size+”}”; } } }Java 收益指数; } 公共void集合索引(int索引){ 这个指数=指数; } 公共字符串getName(){ 返回名称; } 公共void集合名(字符串名){ this.name=名称; } 公共整数getAge(){ 回归年龄; } 公共无效设置(整数){,java,parsing,arraylist,Java,Parsing,Arraylist,收益指数; } 公共void集合索引(int索引){ 这个指数=指数; } 公共字符串getName(){ 返回名称; } 公共void集合名(字符串名){ this.name=名称; } 公共整数getAge(){ 回归年龄; } 公共无效设置(整数){ 这个。年龄=年龄; } 公共双getSize(){ 返回大小; } 公共无效设置大小(两倍大小){ 这个。大小=大小; } @凌驾 公共字符串toString(){ 返回“数据{“+”name=“+name+”,age=“+age+”,siz
<代码>您是否对代码中的某些特定问题有问题?请考虑创建<代码> map < /代码>,其中<代码>键<代码>将是从行开始的编号,而
值
形成为values@joval:你能写一段代码让我明白吗bettr@eis我不知道我是否纠错了代码…我不是在格式化所需的输出。你的代码有一些特定的问题吗?考虑创建<代码> map <代码>,其中,键
将是从行开始的数字,值
形成一个values@joval:你能写一段代码让我明白吗bettr@eis我不知道我是否编写了正确的代码..我没有获得所需的输出这是什么getTopic()函数?它是记录
类中的一个getter,请查看更新。如果此代码也没有获得正确的输出..它将显示一些垃圾值。此getTopic()函数是什么?它是记录
类中的一个getter,请查看更新。如果此代码也没有获得正确的输出..它将显示一些垃圾值。
0 fashioned 0.01
0 hard 0.01
0 taking 0.01
0 cool 0.01
0 conversation 0.01
0 biz 0.01
0 jobs 0.01
0 invest 0.01
1 loving 48.01
1 networks 0.01
1 campaigns 0.01
1 raise 0.01
1 competition 0.01
1 kitten 0.01
1 slashed 0.01
1 planned 0.01
public void wordArray() throws FileNotFoundException, IOException {
ArrayList<Integer> topic = new ArrayList<Integer>();
ArrayList<String> word = new ArrayList<String>();
ArrayList<Double> val = new ArrayList<Double>();
String s,tweet[] = null, d[];
int us = -1;
double max = 0;
FileReader fr = new FileReader("/home/lenovo/abc/words.txt");
BufferedReader br = new BufferedReader(fr);
list1=new ArrayList<Double>();
while ((s = br.readLine()) != null) {
us++;
d = s.split("\t");
topic.add(Integer.parseInt(d[0]));
if(us==0){
list1.add(Double.parseDouble(d[2]));
maxp.put(topic.get(us),list1);
}
else{
maxp.put(Integer.parseInt(d[0]),list1=new ArrayList<Double>());
list1.add(Double.parseDouble(d[2]));
}
class Record {
private final Integer topic;
private final String word;
private final Double value;
public Record(Integer topic, String word, Double value) {
this.topic = topic;
this.word = word;
this.value = value;
}
public static Record valueOf(String recordLine) {
String[] fields = recordLine.split("\\s+");
return new Record(
Integer.valueOf(fields[0]),
fields[1],
Double.valueOf(fields[2])
);
}
public Integer getTopic() {
return topic;
}
public String getWord() {
return word;
}
public Double getValue() {
return value;
}
}
Map<Integer, List<Record>> map = new HashMap<Integer, List<Record>>();
while ((line = br.readLine()) != null) {
Record currRec = Record.valueOf(line);
List<Record> currList = map.get(currRec.getTopic());
if(currList == null) {
currList = new ArrayList<Record>();
map.put(currRec.getTopic(), currList);
}
currList.add(currRec);
import com.fasterxml.jackson.dataformat.csv.CsvMapper;
import com.fasterxml.jackson.dataformat.csv.CsvSchema;
import java.io.IOException;
import java.io.Serializable;
import java.util.Iterator;
import org.apache.commons.collections.map.MultiValueMap;
public class Jackson {
private static final String data = "0\tFirst name\t10\t1.23\n"
+ "1\tSecond name\t23\t\n"
+ "0\tThird name\t30\t1.87";
public static void main(String[] args) throws IOException {
CsvMapper mapper = new CsvMapper();
CsvSchema schema = mapper.schemaFor(Data.class)
.withoutHeader()
.withColumnSeparator('\t')
.withLineSeparator("\n");
Iterator<Data> result = mapper.reader(Data.class).withSchema(schema).readValues(data);
MultiValueMap map = new MultiValueMap();
while (result.hasNext()) {
Data d = result.next();
map.put(d.getIndex(), d);
System.out.println(d);
}
//
// Here is your map
//
System.out.println(map);
}
public static class Data implements Serializable {
private int index;
private String name;
private int age;
private Double size;
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Double getSize() {
return size;
}
public void setSize(Double size) {
this.size = size;
}
@Override
public String toString() {
return "Data{" + "name=" + name + ", age=" + age + ", size=" + size + '}';
}
}
}