Welcome to Dream.In.Code
Become a Java Expert!

Join 149,495 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,356 people online right now. Registration is fast and FREE... Join Now!




how to use arrays instead of the ADT TreeSet by this following code?

 
Reply to this topicStart new topic

how to use arrays instead of the ADT TreeSet by this following code?

javanoob
18 Mar, 2007 - 10:16 AM
Post #1

New D.I.C Head
*

Joined: 18 Mar, 2007
Posts: 1


My Contributions
anybody know how to convert it? if got people know can help me convert?

java

import java.util.*;
import java.io.*;

public class StudAcc
{
public static void main(String args[]) throws Exception
{
TreeSet oldAcc = new TreeSet();
TreeSet currAcc = new TreeSet();
TreeSet gradAcc = new TreeSet();
TreeSet newAcc = new TreeSet();

try
{
readAccounts("F:\\oldAcc.txt", oldAcc);
readAccounts("F:\\currAcc.txt", currAcc);
}

catch(IOException ioe)
{
System.out.println("Cannot open file");
System.exit(1);
}

gradAcc.addAll(oldAcc);
gradAcc.addAll(currAcc);

newAcc.addAll(gradAcc);
newAcc.removeAll(oldAcc);

System.out.println(oldAcc);
System.out.println(currAcc);
System.out.println(gradAcc);
System.out.println(newAcc);

writeFile("F:\\gradAcc.txt", gradAcc);
writeFile("F:\\newAcc.txt", newAcc);

System.out.println("Data save to the file...");
}

public static void readAccounts(String filename, TreeSet accs) throws Exception
{
Scanner sc = new Scanner(new FileReader(filename));
String accName;
int counter = 0;
while (sc.hasNext())
{
accName = sc.next();
counter++;
if ((counter>3) && (counter%2 == 0))
{
System.out.println(accName);
accs.add(accName);
}
}
}

public static void writeFile(String fileName, TreeSet s) throws Exception
{
FileWriter fw = new FileWriter(fileName);
PrintWriter p = new PrintWriter(fw);

//Iterator;
Iterator iter;
iter = s.iterator();
String item="";
while (iter.hasNext())
{
item = (String) iter.next();
p.println(item);
}
p.close();
}
}

*1lacca: added code tags. next time please use them code.gif
User is offlineProfile CardPM
+Quote Post

horace
RE: How To Use Arrays Instead Of The ADT TreeSet By This Following Code?
18 Mar, 2007 - 11:18 PM
Post #2

D.I.C Addict
Group Icon

Joined: 25 Oct, 2006
Posts: 573



Thanked: 5 times
Dream Kudos: 50
My Contributions
I think you need to determine what methods from TreeSet are used and implement equivalents using an array. For example
CODE

accs.add(accName);

you would need to sort the set yourself
User is offlineProfile CardPM
+Quote Post

winniemika
RE: How To Use Arrays Instead Of The ADT TreeSet By This Following Code?
18 Mar, 2008 - 08:43 AM
Post #3

New D.I.C Head
*

Joined: 17 Mar, 2008
Posts: 1

QUOTE(horace @ 19 Mar, 2007 - 12:18 AM) *

I think you need to determine what methods from TreeSet are used and implement equivalents using an array. For example
CODE

accs.add(accName);

you would need to sort the set yourself


i dont really get wat u you mean > <
can u go for more detail ?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 06:02PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month