[Beds] Java Question

Darren Parkinson darren.parkinson at gmail.com
Wed Dec 7 12:33:54 GMT 2005


Did you try my example code?  You will of course need to import
java.util.*to use the ArrayList...

Just copy and paste the following to array.java, then javac array.java:



import java.util.*;

class array {

public static void main(String args[]) {

   ArrayList message = new ArrayList();

   message.add("Hello World");
   message.add("Another Chat Entry");
   message.add("Final entry");

   System.out.println(message); // this obviously just invokes toString...

   // The following uses an iterator which is more efficient than
   // enumerating them manually:

   Iterator itr = message.iterator();

   while (itr.hasNext()) {
      Object element = itr.next(); //obviously use Object as the root of
all..
      System.out.println(element);
   }
}



On 12/7/05, Stephen Elliott <techweb at ntlworld.com> wrote:
>
> Hi,
>
> Cheers for your help guys. I could not get that to work, came up with
> unable
> to resolve symbol errors amongst other things.
>
> Unfortunately my knowledge of Java isn't all that great.
>
> Steve...
>
> -----Original Message-----
> From: 0MMyrtek at oag.com [mailto:0MMyrtek at oag.com]
> Sent: 07 December 2005 08:58
> To: techweb at ntlworld.com
> Subject: RE: [Beds] Java Question
>
>
> Hi ,
>
>
> Try this:
>
>
>
> ArrayList _arrayList = new ArrayList();
> _arrayList.add("blablahbla");
>
>
> for (int j = 0; j < _arrayList.size(); j++) {
>                System.out.println(_arrayList.get(j));
> }
>
> Rgds Mike
>
>
> -----Original Message-----
> From: beds-bounces at mailman.lug.org.uk
> [mailto:beds-bounces at mailman.lug.org.uk] On Behalf Of Stephen Elliott
> Sent: 06 December 2005 14:13
> To: beds at mailman.lug.org.uk
> Subject: [Beds] Java Question
>
>
> Hi there,
>
>
> I have a quick Java question I'd like to run past any Java Gurus out
> there. I am writing a multi-thread chat server programming using RMI and
> want to store all the messages users send to each other in an array. The
> purpose being, when someone new joins the chat room they will receive
> all previous messages users have sent to one another. So far all I can
> do is store a predefined amount e.g. 100. I have achieved this by
> creating a string array with 100 elements. What I would like to do is be
> able to store an infinite number of messages but is it possible to
> create an array with an infinite number of elements.
>
> I hope what I have said makes sense, this is as you've probably guessed
> an assignment we have been given at University. I have asked my lecturer
> and he says this is beyond the scope of the course but to me it seems
> foolhardy to write a program that will crash once 100 messages have been
> relayed.
>
> Many Thanks
> Steve...
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.362 / Virus Database: 267.13.12/192 - Release Date:
> 05/12/2005
>
>
> _______________________________________________
> Beds mailing list
> Beds at mailman.lug.org.uk http://mailman.lug.org.uk/mailman/listinfo/beds
> NOTICE: This e-mail is intended for the named recipient(s). It may contain
> privileged and/or confidential information. If you are not one of the
> intended recipients, please notify the sender immediately and destroy this
> e-mail and attachment(s): you must not copy, distribute, retain or take
> any
> action in reliance upon the email or attachment(s). While all reasonable
> efforts are made to safeguard inbound and outbound e-mails, OAG Worldwide
> Ltd and its affiliate companies cannot guarantee that attachments are
> virus-free or are compatible with your systems, and does not accept
> liability in respect of viruses or computer problems experienced. Thank
> you.
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.371 / Virus Database: 267.13.12/193 - Release Date:
> 06/12/2005
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.371 / Virus Database: 267.13.12/193 - Release Date:
> 06/12/2005
>
>
> _______________________________________________
> Beds mailing list
> Beds at mailman.lug.org.uk
> http://mailman.lug.org.uk/mailman/listinfo/beds
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.lug.org.uk/pipermail/beds/attachments/20051207/ab4cb24a/attachment.html


More information about the Beds mailing list