| | |
Printing out specpfic elements in arrayList
![]() |
•
•
Join Date: Feb 2009
Posts: 8
Reputation:
Solved Threads: 0
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?
Java Syntax (Toggle Plain Text)
for( int i = 0; i < words.length; i++ ){ System.out.println( words[ i ] ); }
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
![]() |
Other Threads in the Java Forum
- Previous Thread: Illegal Start of expression
- Next Thread: Print Registry Folder Contents
| Thread Tools | Search this Thread |
-xlint add android api applet application applications array arrays automation bank bi binary blackberry bluetooth chat class client code compile compiler component database development digit eclipse equation error event fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image infinite input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying pearl problem program programming project qt recursion scanner screen scrollbar server set sms sort sorting spamblocker sql sqlserver string superclass swing system text-file thread threads tree variablebinding windows xor






