forked from jimenbian/DataMining
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
49 lines (41 loc) · 1.45 KB
/
Main.java
File metadata and controls
49 lines (41 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.awt.List;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
public class Main {
public static void main (String[] args) throws IOException{
BufferedWriter writer = new BufferedWriter(new FileWriter(new File("/Users/hakuri/Desktop/data2.txt")));
BufferedReader reader=new BufferedReader(new FileReader(new File("/Users/hakuri/Desktop/final.txt")));
String lineTxt = null;
int i=1;
// ArrayList<String> brand = new ArrayList<String>();
HashMap<String,ArrayList> custom=new HashMap<String,ArrayList>();
while((lineTxt = reader.readLine()) != null){
//System.out.println(lineTxt);
String line=lineTxt.trim();
String[] part=line.split(",");
if(!custom.containsKey(part[0])){
custom.put(part[0],new ArrayList());
custom.get(part[0]).add(part[1]);
}
else{
custom.get(part[0]).add(part[1]);
}
// custom.put(part[0], part[1]);
}
//System.out.print(custom);
Iterator<String> it=custom.keySet().iterator();
while( it.hasNext()){
String key=(String)it.next();
ArrayList value=custom.get(key);
System.out.println(key+"--"+value);
}
//System.out.println(custom.keySet().iterator());
}
}