I have a situation as below. If I use usual for loop, it is very time consuming. I have a list of UserRating. Structure of UserRating is as below.
public class UserRating {
private String userId;
private String productId;
private int rating;
// getters and setters
}
Example of data for UserRating (userId, productId, rating in the order)
U1, P1, 1
U1, P2, 3
U2, P2, 5
U7, P1, 2
U7, P5, 4
I want to replace the alpha-numeric userId and productId with integer starting from 1. I want to achieve the below output for above data. The rating should be kept same as it is.
1, 1, 1
1, 2, 3
2, 2, 5
3, 1, 2
3, 3, 4
The most important point: I am processing about 5.5 million records. I have already these records in csv file. I read it using java 8 stream API and keep it as `list. Main code where search and replace happens: userTemp and userTemp2 have same elements. Actually in this code, I am just trying to do the replacement for a single column in csv (e.g userId).
for (String original : userTemp) {
cnt1++;
if (cnt1 % 10000 == 0) {
System.out.println(cnt1 + " processed");
}
if (userTemp2.contains(original)) {
countI++;
Collections.replaceAll(userTemp2, original, String.valueOf(countI));
}
}
Comments
Post a Comment