It's not a secret anymore!
The moose likes Java in General and the fly likes Reading data to an ArrayList<Point> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Reading data to an ArrayList<Point>" Watch "Reading data to an ArrayList<Point>" New topic

Reading data to an ArrayList<Point>

Ryan Callen

Joined: Nov 29, 2012
Posts: 22
Can somebody explain to me the most efficient way to read in data from a text file and organize it into an ArrayList<Point>?

Let's say I have a file called "points.txt" and I need to write a method that will read those values in to my program and organize them into an ArrayList<Point> that I can then return to my main. How would I go about doing that? I understand the basic function of IO, but I seem to be confused with the concept of Points, especially in an ArrayList. Thanks!
Greg Charles

Joined: Oct 01, 2001
Posts: 2968

Are you talking about java.awt.Point or some other class? In any case, the first thing to do is figure out how to read the file a line at a time (assuming the text file is arranged so that the data for one Point appears on one line). Try just printing the lines as you read them at first.

The next thing you have to figure out is how to parse one line into the data you need for a Point, but don't worry about that until you get reading from the file working.
I agree. Here's the link:
subject: Reading data to an ArrayList<Point>
It's not a secret anymore!