I want to store number in two dimensional format. For eg.
in JSP. Maximum I can have 5000 elements (Guess). I have to process a text file and add the value pair if certain crieterias are satisfied. So I don't know the value of n before hand. It may be required to sort on col1 and col2.
Kindly advise me the data structure that I can use to process this. I am a newbie to JSP/Java.
1. create a simple class which can hold the two numbers
2. implement Comparable on this class
3. stick these objects in an ArrayList
Being a novice to both JSPs AND Java is a big problem by the way. I wouldn't touch web development until you've spent a little more time studying core Java; the language, the tools and the platform. Its already difficult enough when you don't try to run before you can walk.
The language also lets you use 2-dimensional arrays, but it's less robust & more error-prone than the other suggestion about a class to hold the two numbers. I invented such a class for my own use a long time ago. Being a very creative person, I named it Pair. Declared it as public class Pair<F, S> so it could hold two of anything. And, wonder of wonders, I also have a class called Triplet !
Being a very creative person, I named it Pair. Declared it as public class Pair<F, S> so it could hold two of anything.
This is indeed a good approach.
But keep in mind that you cannot parameterize your type with primitives (<tt>new Pair<int,long>(1,3)</tt>). Autoboxing my be your friend then (<tt>new Pair<Integer,Long>(1,3)</tt>) but you'll have to remember that when facing memory issues...