I have a file like this
Petal_Length 0 1.3 - 2.42
Petal_Length 1 2.42 - 3.54
Petal_Length 2 3.54 - 4.66
Petal_Length 3 4.66 - 5.78
Petal_Length 4 5.78 - 6.9
Petal_Width 5 0.3 - 0.76
Petal_Width 6 0.76 - 1.2200000000000002
Petal_Width 7 1.2200000000000002 - 1.6800000000000002
Petal_Width 8 1.6800000000000002 - 2.14
Petal_Width 9 2.14 - 2.6
Sepal_Length 10 4.3 - 5.02
Sepal_Length 11 5.02 - 5.739999999999999
Sepal_Length 12 5.739999999999999 - 6.459999999999999
Sepal_Length 13 6.459999999999999 - 7.179999999999999
Sepal_Length 14 7.179999999999999 - 7.899999999999999
Sepal_Width 15 2.3 - 2.76
Sepal_Width 16 2.76 - 3.2199999999999998
Sepal_Width 17 3.2199999999999998 - 3.6799999999999997
Sepal_Width 18 3.6799999999999997 - 4.14
Sepal_Width 19 4.14 - 4.6
I am trying to group this data as
Petal_Length[0:1.3 - 2.42,1:2.42 - 3.54,2:3.54 - 4.66,3:4.66 - 5.78,4:5.78 - 6.9]
This is a way of grouping. My goal is to get the attribute name index and range.
Use hashmap?
UPDATE
What I've done -
while((line = bf.readLine())!=null){
String featureVal[] = line.split("\t");
val.add(featureVal[0]);
listToSet = new HashSet<String>(val);
attributeVal = new ArrayList<String>(listToSet);
binMap.put(featureVal[0], new ArrayList<String>());
String[] cols = featureVal[1].split("\t");
for(int i = 0; i < cols.length; i++) {
if(attributeVal.get(i).equals(cols[i])){
System.out.println("in foorlop");
List<String> tmpList = binMap.get(attributeVal.get(i));
if(tmpList == null) {
tmpList = new ArrayList<String>();
}
System.out.println("cols[i]"+cols[i]);
tmpList.add(cols[i]);
binMap.put(attributeVal.get(i), tmpList);
}
}
System.out.println("binMap: "+binMap);
}
But my output is null
binMap: {Petal_Width=[], Sepal_Length=[], Petal_Length=[], Sepal_Width=[]}
Please offer.
source
share