Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.HashSet; public class Main { public static ArrayList<Double> stringToDoubleListRemoved(String s, String delimeter, int[] fieldsToBeRemoved) { ArrayList<Double> ret = new ArrayList<Double>(); ArrayList<Double> allFields = stringToDoubleList(s, delimeter); HashSet<Integer> toBeRemoved = new HashSet<Integer>(); for (int i : fieldsToBeRemoved) toBeRemoved.add(i); for (int i = 0; i < allFields.size(); i++) { if (toBeRemoved.contains(i)) continue; ret.add(allFields.get(i)); } return ret; } /** * * @param s * @param delimeter * @param fieldsToBeKept: idxes of the fields to be kept * @return */ public static ArrayList<Double> stringToDoubleList(String s, String delimeter, int[] fieldsToBeKept) { ArrayList<Double> ret = new ArrayList<Double>(); ArrayList<Double> allFields = new ArrayList<Double>(); for (int i = 0; i < fieldsToBeKept.length; i++) { ret.add(allFields.get(fieldsToBeKept[i])); } return ret; } public static ArrayList<Double> stringToDoubleList(String s, String delimeter) { String[] fields = s.split(delimeter); ArrayList<Double> ret = new ArrayList<Double>(); for (int i = 0; i < fields.length; i++) { ret.add(Double.parseDouble(fields[i].trim())); } return ret; } }