Extracting coordinates file that are inside a bounding box I'm scanning a CSV file to see which values fit inside of a given box. The CSV file has X and Y coordinates, and the arguments to the function are the perimeters of a box (i.e, top, bottom, left side, right side). I don't want to use any external libraries; part of the purpose of this is to learn how to speed up code manually.

I'm fairly new to Java, so any input would be helpful. I'm trying to get this down to 100ms if possible, but right now it's taking about 1000ms.

Scanner dataStream = new Scanner(fileMain);
while (dataStream.hasNext()){
    String data = dataStream.next();
    String[] values = data.split(",", 3);
    if(Double.parseDouble(values[0]) &gt; lowX &amp;&amp; Double.parseDouble(values[0]) &lt; highX){ 
            if(Double.parseDouble(values[1]) &lt; highY &amp;&amp; Double.parseDouble(values[1]) &gt; lowY){
                System.out.println(data);

    }

dataStream.close();


Data is formatted like so:

90.92, 102.3
40.28, 82.32
13.02, 80
72, 104.82
First of all, note that you can always use Point2D.Double for representing points in a plane.

Next, I would split your program into two methods: the first one for pruning points that are not within a specified bounding box, and the second one for reading the points from the standard input, and putting them into the first one.

What comes to coding conventions, I would have a blank line before the if statement. Also, you should surround the condition of an if statement with a single space. So, instead of 

String[] values = data.split(",", 3);
if(Double.parseDouble(values[0])){ ...


you should write 

String[] values = data.split(",", 3);

if (Double.parseDouble(values[0])) { ...


All in all, I had this in mind:

import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Scanner;

public class CoordinateUtilities {

    public static List&lt;Point2D.Double&gt; 
        getPointsWithinBoundingBox(final List&lt;Point2D.Double&gt; pointList,
                                   final double lowX,
                                   final double highX,
                                   final double lowY,
                                   final double highY) {
        Objects.requireNonNull(pointList, "The list of points is null.");
        checkXBounds(lowX, highX);
        checkYBounds(lowY, highY);
        final List&lt;Point2D.Double&gt; ret = new ArrayList&lt;&gt;(pointList.size());

        for (final Point2D.Double point : pointList) {
            final double x = point.x;
            final double y = point.y;

            if (lowX &lt;= x &amp;&amp; x &lt;= highX &amp;&amp; lowY &lt;= y &amp;&amp; y &lt;= highY) {
                ret.add(point);
            }
        }

        return ret;
    }

    public static void main(final String... args) {
        final Scanner scanner = new Scanner(System.in);
        final double lowX  = 50.0; 
        final double highX = 100.0;
        final double lowY  = 30.0;
        final double highY = 60.0;

        final List&lt;Point2D.Double&gt; allPoints = new ArrayList&lt;&gt;();

        while (scanner.hasNextLine()) {
            final String line = scanner.nextLine();

            if (line.trim().equals("quit")) {
                break;
            }

            final Point2D.Double point = parsePoint(line);

            if (point != null) {
                allPoints.add(point);
            }
        }

        final List&lt;Point2D.Double&gt; boundedPoints = 
                getPointsWithinBoundingBox(allPoints, lowX, highX, lowY, highY);

        boundedPoints.forEach(System.out::println);
    }

    private static Point2D.Double parsePoint(final String line) {
        final String[] tokens = line.trim().split("\\s*,\\s*");

        if (tokens.length &lt; 2) {
            return null;
        }

        try {
            final double x = Double.parseDouble(tokens[0]);
            final double y = Double.parseDouble(tokens[1]);
            return new Point2D.Double(x, y);
        } catch (final NumberFormatException ex) {
            return null;
        }
    }

    private static void checkXBounds(final double lowX, final double highX) {
        if (Double.isNaN(lowX)) {
            throw new IllegalArgumentException(
                    "The lower bound of the x-coordinate is NaN.");
        }

        if (Double.isNaN(highX)) {
            throw new IllegalArgumentException(
                    "The upper bound of the x-coordinate is NaN.");
        }

        if (lowX &gt; highX) {
            throw new IllegalArgumentException(
                    "The lower bound of the x-coordinate (" + lowX + "is " +
                    "larger than the upper bound of the x-coordinate (" +
                    highX + ").");
        }
    }

    private static void checkYBounds(final double lowY, final double highY) {
        if (Double.isNaN(lowY)) {
            throw new IllegalArgumentException(
                    "The lower bound of the y-coordinate is NaN.");
        }

        if (Double.isNaN(highY)) {
            throw new IllegalArgumentException(
                    "The upper bound of the y-coordinate is NaN.");
        }

        if (lowY &gt; highY) {
            throw new IllegalArgumentException(
                    "The lower bound of the y-coordinate (" + lowY + "is " +
                    "larger than the upper bound of the y-coordinate (" +
                    highY + ").");
        }
    }
}


Hope that helps.