Printing out specpfic elements in arrayList

Reply

Join Date: Feb 2009
Posts: 8
Reputation: VinceAshbySmith is an unknown quantity at this point 
Solved Threads: 0
VinceAshbySmith VinceAshbySmith is offline Offline
Newbie Poster

Printing out specpfic elements in arrayList

 
0
  #1
Mar 20th, 2009
HI all wonder if someone can help, i want to be able to printout specific elements within an arrayList without using array keys. I have the following code, which will print out every element in the array. I want to print out every 2nd element. So so i had a array containing 1,2,3,4,5,6,7,8,9,10, what i want to be able to do is print out every 2nd element, so end up with 2,4,6,8,10. Any ideas?

  1.  
  2. for( int i = 0; i < words.length; i++ ){
  3. System.out.println( words[ i ] );
  4. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3,584
Reputation: jasimp has a spectacular aura about jasimp has a spectacular aura about jasimp has a spectacular aura about 
Solved Threads: 52
Featured Poster
jasimp's Avatar
jasimp jasimp is offline Offline
Senior Poster

Re: Printing out specpfic elements in arrayList

 
0
  #2
Mar 20th, 2009
I'm confused what you mean by array keys. You also say you want to print specific elements in an ArrayList, then change and say Array. In any case, with the code you have provided, just change i++ to i+=2 That will print out every 2nd element.
"Argyou not with the hand you are dealt in cards or life." ---- Wizard and Glass
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC