[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Få tilfældigt element af list i Java



Hej,

Hvordan kan man få et tilfældigt valgt element fra en list i Java?

Hvis man har en liste der fx indeholder lidt adresser, hvordan får man så printet en tilfældig adresse ud?

Jeg har noget som:

ArrayList list2 = new ArrayList();
try {
BufferedReader targetFile2 = new BufferedReader(new FileReader("random.txt"));
String targetString2 = "";
while((targetString2= targetFile2.readLine()) != null){
list2.add(targetString2);
}
}


plus lidt exception indfangning. Nu kunne jeg så godt tænke mig, at få et tilfældigt element ud fra list2. Hvordan gør jeg det?

Anders

 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 22:44 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *