The below is an example of a text file from PDB.

ATOM 2 CA ASP E 423 -50.931 46.011 -16.062 1.00153.24 C
ATOM 3 C ASP E 423 -51.314 44.692 -15.381 1.00152.70 C
ATOM 4 O ASP E 423 -52.175 44.673 -14.497 1.00153.08 O
ATOM 5 CB ASP E 423 -51.993 46.400 -17.101 1.00153.44 C
ATOM 6 CG ASP E 423 -53.276 46.931 -16.464 1.00154.12 C
ATOM 7 OD1 ASP E 423 -53.246 48.037 -15.879 1.00156.34 O
ATOM 8 OD2 ASP E 423 -54.318 46.247 -16.557 1.00154.62 O
ATOM 9 N LEU E 424 -50.675 43.600 -15.805 1.00151.30 N
ATOM 10 CA LEU E 424 -50.864 42.271 -15.208 1.00149.56 C
ATOM 11 C LEU E 424 -50.526 42.277 -13.715 1.00147.96 C

As you can see, the highlighted numerals are the X,Y & Z coordinates. How do I store them in an array, row by row so that I can multiply them using matrix (translation/rotation). The format of the file remains the same(.pdb) which can be opened in notepad++.

Read the values store/retrieve from Coordinates object

public class Coordinates {
  private double x;
  private double y;
  private double z;
  public Coordinates(){}
  public Coordinates(double x, double y, double z){
  private void setX(double x){
    this.x = x;
  public double getX(){
    return x;
  private void setY(double y){
    this.y = y;
  public double getY(){
    return y;
  private void setZ(double z){
    this.z = z;
  public double getZ(){
    return z;

Use something more flexible then array like List, ArrayList or perhaps Vector

List<Coordinates> coordinates = new ArrayList<Coordinates>();
//read values from file
coordinates.add(new Coordinates(x,y,z));
//rest of code

Thank you, but how do I extract them and then store in the array? Should I use parse/scanner/tokenizer??

Hm, two posters from Singapore asking about the same problem set. What are the odds. Good catch, Tong.

Hazeel - what you use to solve this sort of problem depends largely on the sort of data you have and how it's defined. If there's a fixed-width format, you can read substrings based on character position (see String.substring()). If there's a consistent separator character (or a regex that describes a good separator) you can use split (String.split()) - I like that one when I can use it, because it gives me a nice array to play with. My last resort would be to use a tokenizer to get one instance at a time. I'd only use that if there's a toally free format and you need to do actual parsing, looking at each item and determining what you're doing. You don't need to do that here. (although obviously you'll need a scanner or a BufferedReader or something to get the data from the file in the first place)

Start by getting your lines from the file. Then read up on the String methods (substring and split) and pick one. (I'd suggest split, myself, in this instance) Then try playing with them and see what you get.