I am a M.D., PhD candidate who wants to learn some programming in java.
I am conducting a research on the heart rate variability analysis and I want to make a simple program that would allow me to input an array list from a .txt file, filter some data out, and export the filtered data to a new .txt file. I have made the program in QBasic :), but I want to do it in java too.
I am able to get the first part, how to import an array:
public class random {
public static void main (String[] args) throws FileNotFoundException
{
Scanner s = new Scanner(new File("c:\\data.txt"));
ArrayList<String> list = new ArrayList<String>();
while (s.hasNext()){
list.add(s.next());
}
s.close();
The program should filter repeated double type numbers from the txt file and only print out a unique values to a new txt document. Here you have my original question, where you can see what I mean:
Extraction of unique values form a array list
A user suggested this code, which works perfectly if I insert the numbers by hand.
int[] input = new int[]{0, 0, 0, 0, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 5, 5, 5, 5, 8, 8, 10, 10, 2, 2, 2, 3, 3, 7, 7};
int current = input[0];
boolean found = false;
for (int i = 1; i < input.length; i++) {
if (current == input[i] && !found) {
found = true;
} else if (current != input[i]) {
System.out.print(" " + current);
current = input[i];
found = false;
}
}
System.out.print(" " + current);
Does anyone have suggestions how could I, instead of inserting the numbers by hand, import the array list from a text file and filter the data using the for loop in the previous code?