The Artima Developer Community
Sponsored Link

Java Answers Forum
Sorting Multidimensional Array

4 replies on 1 page. Most recent reply: Apr 3, 2007 3:46 PM by Jonathan Davids

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
Jonathan Davids

Posts: 11
Nickname: jonat
Registered: Mar, 2007

Sorting Multidimensional Array Posted: Mar 22, 2007 3:41 PM
Reply to this message Reply
Advertisement
Hello,

I am new to Java and wanted to read and sort a flat file line by line e.g.:

1¦A,C,F,G,A
2¦Baby,H,K,A,C
3¦Oslo,S,F,T,K

so that after reading the first line, I will have 2A, 1C, 1F, 1G as result. There after, I can read the second line and have 1Baby, 1H, 1K, 1A and 1C as result. I can then add the result of both lines to get 3A, 2C, 1H, 1K, 1F and 1Baby as result ...

Can someone help me to realize it.

Thanks,
Jonat


Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: Sorting Multidimensional Array Posted: Mar 23, 2007 3:12 AM
Reply to this message Reply
Post some evidence that you have made some attempt to solve the problem yourself and we'll see if we can help you with the part you can't do.

Jonathan Davids

Posts: 11
Nickname: jonat
Registered: Mar, 2007

Re: Sorting Multidimensional Array Posted: Mar 23, 2007 11:05 AM
Reply to this message Reply
DataInputStream dis = null;
	String line = null;
	
	String [][]result = new String[100][100];
	LinkedList<String []> dataList = new LinkedList<String []>();
	
	
	try {
		
		    File data = new File("C:/test.txt");
			FileInputStream in = new FileInputStream(data);
			dis = new DataInputStream (in);
			BufferedReader br = new BufferedReader(new InputStreamReader(dis));
			line  = br.readLine();
			
	while (line != null) {
				dataList.add(line.split(" "));
	}
.
.
.
.
 


From here, I tried first to use StringTokenization but it did not work (not getting the right answers). I tried using line.split(¦,) to split each line but it did also not work.
I just need some hints to continue after spending some days trying to solve it.

Thanks

Jonat

Pete Burkindine

Posts: 4
Nickname: repeat2341
Registered: Apr, 2007

Re: Sorting Multidimensional Array Posted: Apr 3, 2007 11:50 AM
Reply to this message Reply
The set data structure has useful methods for creating set unions. Finding the union of two sets is part of your problem. The other could be solved using compound "Entry" objects (a nested internal class) with simple data members to store the string and a counter.

Jonathan Davids

Posts: 11
Nickname: jonat
Registered: Mar, 2007

Re: Sorting Multidimensional Array Posted: Apr 3, 2007 3:46 PM
Reply to this message Reply
Hello,
Thanks for the advice.

Flat View: This topic has 4 replies on 1 page
Topic: Sorting Multidimensional Array Previous Topic   Next Topic Topic: Printing Correct Portions of a Recursion

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use