🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #735

list class

#735
From: Scott
Date: Thu, 16 Dec 2004 18:49
82 lines
3796 bytes
I appreciate the help, however I'm a bit lost with the code that's missing. 
Having issues as to what is needed. Maybe I need more of an obvious hint as 
to what goes...where.  Remember i'm working on my own, so I may need more 
info than provided. I only have the Java documentation, and a book from the 
library.  Please help.

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]
>   }
> }
Technical Details
Message-ID: <0Nkwd.12381$Ae.6831@newsread1.dllstx09.us.to.verio.net>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!news.moat.net!newspeer1.mlpsca01.us.to.verio.net!verio!newsread1.dllstx09.us.to.verio.net.POSTED!53ab2750!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f74b3,62cee13431c73458,start
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!news.moat.net!newspeer1.mlpsca01.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
Subject: list class
Lines: 84
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
Message-ID: <0Nkwd.12381$Ae.6831@newsread1.dllstx09.us.to.verio.net>
Date: Thu, 16 Dec 2004 13:49:31 -0500
NNTP-Posting-Host: 209.139.23.142
X-Complaints-To: abuse@verio.net
X-Trace: newsread1.dllstx09.us.to.verio.net 1103222972 209.139.23.142 (Thu, 16 Dec 2004 18:49:32 GMT)
NNTP-Posting-Date: Thu, 16 Dec 2004 18:49:32 GMT
Organization: NTT/VERIO