This discussion is archived
5 Replies Latest reply: Nov 19, 2012 12:29 PM by gimbal2 RSS

Datastructure Suggestion

Subbu Newbie
Currently Being Moderated
Hi,

I want to store number in two dimensional format. For eg.

123124,145785
123487,854214
.
.
.
.
n elements

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.

Regards,
Subbu S.
  • 1. Re: Datastructure Suggestion
    gimbal2 Guru
    Currently Being Moderated
    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.
  • 2. Re: Datastructure Suggestion
    Subbu Newbie
    Currently Being Moderated
    Thanks for your revert
  • 3. Re: Datastructure Suggestion
    aksarben Journeyer
    Currently Being Moderated
    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 !

    [Sorry, this was intended as a reply to OP.]
  • 4. Re: Datastructure Suggestion
    TPD-Opitz-Consulting-com Expert
    Currently Being Moderated
    aksarben wrote:
    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...

    bye
    TPD
  • 5. Re: Datastructure Suggestion
    gimbal2 Guru
    Currently Being Moderated
    aksarben wrote:
    [Sorry, this was intended as a reply to OP.]
    Eh? Oh, I don't even register that forum feature. I react to quoted posts only.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points