• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Make for loop still execut while somehow counting up every x times

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to do this because I want to add multiple arrays to one ArrayList to manage them better. Here is what I tried so far:

Size is how big the steps should be in that I want to count up, but it is also how many loops should be going through without counting up.
I don't know if I just searched the wrong thing but I couldn't find anything...
Thank you!
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We need a little more context to answer the question. For one thing you are using array syntax to access your "arrayList", so, is it an array or is it an ArrayList? How are you creating and initializing "arrayList"?
 
Peter Seeger
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, sorry didn't know this was a problem:

So, thats the entire code!
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Seeger wrote:Oh, sorry didn't know this was a problem:

Line 1 your are missing the type of the inner ArrayList.
Line 9 your are missing the type of the ArrayList.
This would seem a little cleaner.
Lines 9-15 have nothing to do with getArrays().
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the code where you are calling getArrays()?
EDIT:
It looks like you're calling it from sortArrays(). How is sortArrays() being called?
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This seems overly complex. Can you describe in English what your overall requirements are?
 
Peter Seeger
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:This seems overly complex. Can you describe in English what your overall requirements are?


Sorry I am just experenting with some things. Still appreciate your patience! I want someting in a for loop to run through every time (Yes, that works!) But the variable that you are counting up to end the loop at some point should only increase e.g every five times.
 
Rancher
Posts: 285
14
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think a while loop would be better for increment every 5, something like this?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Seeger wrote:I want someting in a for loop to run through every time (Yes, that works!) But the variable that you are counting up to end the loop at some point should only increase e.g every five times.



Normally when you write a for loop with a counter as its index, the loop-ending value is constant. So perhaps it's the index variable which you want to increase every five times? But that doesn't make any sense to me either; do you really want the index variable to go 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, ... and so on? I suspect not.

In which case I'm stuck. Your code doesn't help, but that isn't surprising because you tried to write it to explain your problem even though writing the code is the thing you're having a problem with. So I agree with Carey -- an English description of what you want to do would be a good start. An English description which doesn't use the words "array" or "list" would be even better.
 
S Fox
Rancher
Posts: 285
14
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in my example above i forgot to increment the x outside the if-statement so, infinite loop. oops. i guess he wanted 2 vars for this anyhow.
 
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Seeger wrote:I want to add multiple arrays to one ArrayList to manage them better


If your task is to merge two Arrays to a List, fairly easy way of doing this is:


If you need to merge more arrays, you could add some more code around this.

One other way to do is:
 
reply
    Bookmark Topic Watch Topic
  • New Topic