read the csv file on indices base
The for csv cell value is ABCDEFGHIJK Read csv file like "A","BCD", "EFGH","IJK" based on the character value like - [1,2,5,9]
import com.opencsv.CSVReader;
import java.io.FileReader;
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String[] args) throws Exception {
// Define the indices to extract
List<Integer> indices = Arrays.asList(1, 2, 5, 9);
// Create a CSVReader
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));
// Read the CSV file
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
// For each line, concatenate the cell values into a single string
StringBuilder cellValues = new StringBuilder();
for (String cell : nextLine) {
cellValues.append(cell);
}
// Extract the characters at the specified indices
for (int index : indices) {
if (index < cellValues.length()) {
System.out.println("Character at index " + index + ": " + cellValues.charAt(index));
}
}
}
reader.close();
}
}