Article View: borland.public.jbuilder.java.language
Article #732Re: list class (long)
From: Scott
Date: Wed, 15 Dec 2004 21:11
Date: Wed, 15 Dec 2004 21:11
112 lines
5183 bytes
5183 bytes
Joerg,
That was definately a great start. However, i'm not in a class or anything
like that, so I'm sort of on my own. It's not necessarilly a required
project, just sort of something I thought would help me understand array and
the language a little better. I'm not a huge programmer, I have some
experience in Visual Basic, and C++(Many years ago). This definately is
good and will play aorund with this tonight.Any other help would be great,
either bit sof code or just some ideas of things to use. I'm learning this
on my own and have a book to refer to and the Java help files themselves,
which are terribly intuitive to a new student of the language. Again, thanks
for the help you've given me already, and any other bits of code or tips
would be appreciated.
Cheers,
Scott
> Scott wrote:
> [snip]
>> I want to createa class called List that will remember a list of
>> strings. It'll (hopefully) have methods that will do the following.
> [snip]
>> I'd like to be able to sory in alphabetical and something I can use
>> this list to maintain an email list. Any help anyone can provide
>> would be great. Thanks in advance
>
> It didn't really figured out how much help you really want, because you
> said you want to learn Java.
>
> First, to melp me or others who maybe post later some interesting
> questions:
> Do you still want to use the new features of Java 1.5 (like generic
> programming)?
> Do you have any prior knowledge in programming
> Do you study something in this way, do something in school, work with it?
> Most important to me ^^: *Do you still know data structures*?
>
>
> So now a litte help, not to much, say if its not enough, ore didn't helped
> at all ;).
>
> You wand a class holding Strings, and doing String compare things.
> You want this class to shrink ore increase in size.
>
> Thats not that hard, because you can use a prebuild Java Container, a
> *ArrayList* (like a Vector in C++ [there is a Vector in Java too, same as
> array list, but older]).
>
> An ArrayList can increase and shrink in size automatically, and has
> methods to put data inside [put()] and get data from it [get()].
> The items in the ArrayList are stored in the order you put them in.
>
> because a ArrayList shrink and increases by itself, i don't think if you
> make it this way, it would make sence to set the size at the beginning.
>
> So your class could look like this:
>
> import java.util.ArrayList;
>
> public class Line {
> private ArrayList myWords;
>
> Line() {
> myWords = new ArrayList(); // if you want 4: new ArrayList(4);
> }
>
> public void add(String s) {
> myWords.add(s);
> }
>
> public void contains(String s) {
> myWords.contains(s);
> }
>
> // don't show you all, look in the Java documentation
> // on developer.java.sun.com
>
> public String get(int n) {
> return ((String) myWords.get(n));
> // wow: whats that?
> // if you store in an ArrayList until
> // Java 1.4.2 the object will have forgotten its
> // type, its noe of type object
> // So you have to cast to get the right object back
>
> // hoever: in 1.5 you don't have to cast ^^ [generic programming]
> }
> }
>
> so you would just let your functions deligate to the ones of ArrayList.
>
> There shure are other ways to do so.
> If you want to explore more of data structures you may for instance want
> to to it as a linked list.
> Or you implement it simply with an array, but use a binary search to get
> the date.
>
> Like allways there are MANY possibilities to do so ^^
>
> hope this helped
> cu
> Joerg
>
>
> --
> --------------------------------------------------------------
> Elrond_III -==: Hack the World :==-
> g:R->R; [a,b] in D(g) and g[a,b] in [a,b] and for all x1,x2 in [a,b]
> |g(x1)-g(x2)|<=L*|x1-x2| with L <= 1 then one s in [a,b] exist with
> s=g(s)
> -"Banachscher Fixpunktsatz"
Technical Details
Message-ID:
<0M1wd.12357$Ae.2298@newsread1.dllstx09.us.to.verio.net>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.dllstx09.us.to.verio.net!verio!newsread1.dllstx09.us.to.verio.net.POSTED!53ab2750!not-for-mailReferences:
<4XHvd.12318$Ae.1427@newsread1.dllstx09.us.to.verio.net> <41bf6f1c$0$22342$3b214f66@aconews.univie.ac.at>Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,3f0cbc3440ab15d9 X-Google-Attributes: gidf74b3,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.dllstx09.us.to.verio.net!verio!newsread1.dllstx09.us.to.verio.net.POSTED!53ab2750!not-for-mail From: "Scott" <swurm@suffolk.lib.ny.us> Newsgroups: borland.public.jbuilder.java.language References: <4XHvd.12318$Ae.1427@newsread1.dllstx09.us.to.verio.net> <41bf6f1c$0$22342$3b214f66@aconews.univie.ac.at> Subject: Re: list class (long) Lines: 114 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Response Message-ID: <0M1wd.12357$Ae.2298@newsread1.dllstx09.us.to.verio.net> Date: Wed, 15 Dec 2004 16:11:19 -0500 NNTP-Posting-Host: 209.139.23.142 X-Complaints-To: abuse@verio.net X-Trace: newsread1.dllstx09.us.to.verio.net 1103145084 209.139.23.142 (Wed, 15 Dec 2004 21:11:24 GMT) NNTP-Posting-Date: Wed, 15 Dec 2004 21:11:24 GMT Organization: NTT/VERIO