permaculture playing cards*
The moose likes Beginning Java and the fly likes declaring array of vectors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "declaring array of vectors" Watch "declaring array of vectors" New topic
Author

declaring array of vectors

Puneet N Vyas
Ranch Hand

Joined: Sep 20, 2007
Posts: 61
i have a text file with following enteries:
12345 2145 0912
4356 0981 2134

now i want to declare the vector according to the number of lines the text file is containing,i wrote the following code but it didn't work:





//scalable sequential pattern mining

import java.io.*;
import java.util.*;
public class sspm
{

//static int numberofsequences;
//method for counting the number of sequences in the IBM data file
/*int count()

{
try
{
File f = new File("C:\\Program Files\\MyProjects\\final sspm\\sspm\\data1.txt");
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
LineNumberReader lnr = new LineNumberReader(br);
String line;



}

catch (IOException e)
{
e.printStackTrace();
}


return numberofsequences;
}*/
public static void main(String args[])
{

//Vector Transaction[] =new Vector();
//declaring array of transactions to hold individual transactions

//sspm s1=new sspm();
//int sequencesl=s1.count();

int numberofsequences=0;
try {



//vector for holding transactions
// files descriptors for accessing individual data files
File f = new File("C:\\Program Files\\MyProjects\\final sspm\\sspm\\data1.txt");

FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
LineNumberReader lnr = new LineNumberReader(br);
String line;
String temp[];

int spcount[] = new int[10];


//for counting the number of sequennces


while((line=br.readLine())!=null)
{
numberofsequences++;

}


//storing individual transactions in the array of vectors

System.out.println("total number of sequences in the data file are:"+numberofsequences);
File f1 = new File("C:\\Program Files\\MyProjects\\final sspm\\sspm\\data1.txt");
FileReader fr1 = new FileReader(f1);
BufferedReader br1 = new BufferedReader(fr1);
LineNumberReader lnr1 = new LineNumberReader(br1);
String line1;











Vector []transactions=new Vector[numberofsequences];

int index =0;
while((line1=br1.readLine())!=null &&index<=numberofsequences )
{
System.out.println(line1);
//numberofsequences--;
StringTokenizer st=new StringTokenizer(line1);



while (st.hasMoreElements( ))
{


String s1 = (String)st.nextElement();


transactions[index].add(s1);


//System.out.println("number of transactions in sequence "+ numberofsequences +" are "+ length);
//index++;
}

long length = transactions[index].size();
index++;
System.out.println("first vector size is"+length);



}
//System.out.println("total number of sequences in the data file are:"+numberofsequences);



} //end of try block

catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
//System.out.println(Transaction.size());
//System.out.println(Transaction.size());
}
}
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3606
    
  15
Originally posted by fundupuneet vyas:
i wrote the following code but it didn't work:


In what way did it not work ? Does it compile (if not tell us what the error messages are - with an indication of which lines in your code they refer to). If it compiles but does not do what you wanted, then tell us what it is doing and how this differs from what you want it to do.


Joanne
 
GeeCON Prague 2014
 
subject: declaring array of vectors