[Solved] Split an array into small sections

Hi

When working on my project, I am needing to split an array into a hashmap where the index is used to access a smaller array of objects. Any ideas / thoughts would be helpful :slight_smile:

CopyableCougar4

Just wondering why exactly do you need this?

In my project the user has a list of upgrades they can use and I want to have a page system to display them. However, I am open to simpler solutions if you have any :slight_smile:

CopyableCougar4

Once again I solved my problem :frowning: I should really stop posting and just stop and think :slight_smile:

CopyableCougar4

For anybody interested, this is my solution (ignore the variables I haven’t explained, however a lot of them should be easy to figure out). I just only iterate through part of the list.


   int col = 1, row = 1;
		for(int active = ((currentPage - 1) * columns * rows); 
				active < (Math.min(upgrades.size(), (((currentPage - 1) * columns * rows) + (columns * rows)))); active++){
			Upgrade upgrade = upgrades.get(active);
			if(col == columns){
				row++;
				col = 1;
			}
			//System.out.println(upgrade.getName());
			upgrade.getIcon().draw(x + ((col) * gapDimension), 50.0f + ((row) * gapDimension), upgrade.getIcon().getScale(imageDimension));
			col++;
		}

My thought process before posting a question:

  • Think
  • Google
  • Think some more
  • Google some more
  • Search forums
  • Create topic
  • Profit
    :slight_smile:

Hi

Heh I just do:

  • Is there a problem?
  • JGO
  • …
  • Answer!

CopyableCougar4

Mine is;

  • try to solve the problem on my own.
  • Google.
  • Google again.
  • somehow end up googling a JGO post from 2008
  • Google again with different keywords
  • try to do it myself again
  • cry a little
  • Google again.
  • find 13 stackexchange answers full of people telling the original poster what is more technically correct but none of them answer your specific problem.
  • swallow pride and ask JGO.
  • feel like newbie when given something super painfully obvious as an answer.
  • profit!

That’s why you write your algorithms to crowd-source themselves!
http://gkoberger.github.io/stacksort/
:persecutioncomplex:

Heh, I do:
-Google
-Scratch my head
-Draw pictures of the problem
-Start making a new thread on JGO
-Solve the problem while typing it out
-Profit!