[Beds] Java Question

David Pashley david at davidpashley.com
Wed Dec 7 12:04:09 GMT 2005


On Dec 07, 2005 at 10:08, Stephen Elliott praised the llamas by saying:
> 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...
> 

You're lucky, because I was playing with this yesterday, so I know what
is going on now.

import java.util.*;

List list = new Vector();
list.add("foo");

Iterator it = list.iterator();
while(it.hasNext()) {
   String current = (String)it.next();
   System.out.println(current);
}

You really want to use iterators as it means you can change your list
from say a List to a Set or a Hash and it will still work.

> 
> 
> 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
> 
> 
> 
> 
> 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...

-- 
David Pashley
david at davidpashley.com
Nihil curo de ista tua stulta superstitione.



More information about the Beds mailing list