I have a ratings.dat
file. It contains 5 fields. They are userid, movieid, rating, age, moviename. movieid is unique 1 to 3450. userid 1 to 6400. rating is given out of 5.
I should not use SQL. I want 100% Java code. I have done till now: reading a file in hashmap and printing the content of that file.
import java.io.*;
import java.util.*;
public class Output{
public static void main(String[] args) throws FileNotFoundException, IOException {
HashMap< Integer, String > hash = new HashMap< Integer, String >();
BufferedReader rd = new BufferedReader( new FileReader ("resources/ratings.dat"));
String line = "::";
int i = 0;
while ((line = rd.readLine()) != null){
hash.put(i, line);
i++;
}
for ( int j = 0 ; j < hash.size() ; j++){
System.out.println(hash.get(j));
}
}
}
Then call list.sort().
Instead of list you can use any collection like Set or MAP.
Hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.