-4

I am writing a Java program which creates sequences and save them. I'm looking for the most fitted data structure to save the sequences. I don't know in advance the length of the series, or how many series I will have, and the series can be in different length.

what structure should I use?

donfuxx
  • 11,277
  • 6
  • 44
  • 76
user1798339
  • 57
  • 1
  • 6
  • 5
    Start with Lists http://docs.oracle.com/javase/7/docs/api/java/util/List.html – Anto Mar 25 '14 at 10:00
  • Depends what you want to do with series. Do you want to access elements by address? You want fast insert? Fast search? Fast delete? Try with ArrayList and LinkedList first. – darijan Mar 25 '14 at 10:01

3 Answers3

1

You can use a List (i.e. ArrayList or LinkedList) of Strings for example. If you want to store more information about the sequence I would recommend to write a class named Sequence with a String and your additional information in it.

Markus
  • 1,649
  • 1
  • 22
  • 41
0

It depends on how you want to access the items (sequentially or randomly) but an ArrayList or a LinkedList could be a good start.

Here's a discussion of both: When to use LinkedList over ArrayList?

Community
  • 1
  • 1
Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
0

The data structure basically depends on the type of data you are going to store, and since you are saying that the length is not known in advance, I think you should have a look at Collections in java and then decide which one to use.

Maybe if you provide us a sample data, we might be able to help you better.

anirudh
  • 4,116
  • 2
  • 20
  • 35