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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.