File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Best option for 2 rows data

 
Joana Silva
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello its my first post

I have this input file style



where I add them to a string and I need to save them in any type of structure just like that alignment with 2 columns, so what would my best structure choice and how to do it ?
I thought of using ArrayList but no Idea how to do it.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Joana,

Welcome to JavaRanch!

where I add them to a string and I need to save them in any type of structure just like that alignment with 2 columns, so what would my best structure choice and how to do it ?
I thought of using ArrayList but no Idea how to do it.

I am not clear about your question. How do you want to save them? How are you gonna manipulate/retrieve them? And tell us little about your file structure too.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47272
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch again

Numbers in Java don't have a "format" but can be reformatted when they are printed (or put into a text file) with the % tags. You might do well to create a class which has int and char fields which will record the number and letter. As for putting them into a List, read this Java Tutorials section.

Do your formatting with the % tags, as described in the Formatter class, or here in the Java Tutorials. You can thus alter the format every time you print the data out.
 
Joana Silva
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot to mention that the input file has Chars and number on the seconds column so I have to use a string



this is my code so far :




This is the output [18690 I, 18745 10, 18971 I, 19005 11, 19015 6]

I want to store the data in two columns like in a bidimentional array and do math operations with the second column.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47272
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the nextXXX and hasNextXXX methods of the Scanner class, or the split method of the String class.
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...Or If you want to read from file as you have mentioned in earlier posts, you can use FileReader and wrap it into BufferedReader. And use String#Split method.

Thereafter you can store them into two dimensional array.

Joana Silva wrote:I want to store the data in two columns like in a bidimentional array and do math operations with the second column.

How can you do math operation on string? What does that data represent? How do you want to manipulate them?
(I am still unclear about your requirement.)
 
Joana Silva
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will have to convert the ones with numbers to a int so i can calculate the average from the second column of those wihout Letters and I dont need to read from a file I just copy past the input file on console
 
Vikas Kapoor
Ranch Hand
Posts: 1374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok then you can use Scanner class as suggested earlier. Store the values into plain two dimensional array.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic