• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Divide Arraylist into several parts

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have an ArrayList of similar Strings.

Now I have to partition the lists into multiple lists with several parts.

Here is the sample data set

How can i make the size of sublists several?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Siana Ivanova wrote:How can i make the size of sublists several?


Well, assuming you want to return them all at the same time, how about a List?

There's nothing to stop you storing a List as each element of a List, and yours would then be declared as
  List<List<String>> ...

HIH

Winston
 
Siana Ivanova
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want the size of sublists is dynamic.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Siana Ivanova wrote:I want the size of sublists is dynamic.


Lists are dynamic. That's one of the reasons to use them instead of arrays.

Winston

 
Siana Ivanova
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To know.
My question is not set correctly
I got the following list:

I want my method call Next I first printed two elements, the next call to method print three elements, the next call method again print two elements.
 
Sheriff
Posts: 8064
569
Mac OS X VI Editor BSD Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Siana Ivanova wrote:I want my method call Next I first printed two elements, the next call to method print three elements, the next call method again print two elements.

You don't have enough elements in it to do so, you need 2, 3, 2 = 7 elements. I see you have only 6.

Anyway, problem probably not there. Do you have clear and written somewhere requirements so we could have a look at?
I just read your original question, which I did not understand, and the latest - these do not match. Please try clearly define your problem.
 
Siana Ivanova
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. Sorry!
I have a class, that receives a list of items and divide it into list. Is defined size - a list of how many items are displayed at once.
The class has method next(), that returns next few elements of the list. Is defined size - a list of how many items are displayed at once.

I want this size to be dynamic.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Siana Ivanova wrote:I have a class, that receives a list of items and divide it into list.


So, as I said before, you have a List of Lists - or rather, a List of sublists (which are themselves Lists, as you've already worked out).

And as I also said, you don't have to worry about size, because Java Lists are dynamic.

The only thing you need to do is change your 'lists' definition to
  private List<List<String>> lists;
and add a new sublist for each element.

Winston
 
Siana Ivanova
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much!
 
Of course, I found a very beautiful couch. Definitely. And this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic