Skip to content

Commit

Permalink
HashMap
Browse files Browse the repository at this point in the history
One key to couple values
  • Loading branch information
tiancailibo committed Apr 15, 2014
0 parents commit 533407e
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
6 changes: 6 additions & 0 deletions HashMap/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions HashMap/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MakeResult</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions HashMap/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
Binary file added HashMap/bin/Main.class
Binary file not shown.
Binary file added HashMap/final.txt
Binary file not shown.
49 changes: 49 additions & 0 deletions HashMap/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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());
}

}

0 comments on commit 533407e

Please sign in to comment.