• 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

Help understanding how sublist works

 
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 am taking a data structure class and they are going over subset sublist and I'm very confused.
The only thing I remember from the class is a set of numbers and target number.

Can anyone help me understanding this concept?
I tried looking in the JAVA api but there were no examples.

Thank You.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Your question is a bit vague, so it's hard to know exactly what you're asking.

A list is a sequence of things (those things can be numbers, or any other kind of Java objects). I don't know what you mean by a "target number". A sublist is just a part of a list (for example, of your list has 10 elements, then a list that contains elements 2 to 5 of that list is a sublist of the original list).

A set is a collection of things that has no particular order, and each thing can be in the set only once (you can't have the same thing in a set two times). You can think of a set as a bag of things - the things are not in any particular order in the bag.

You can find detailed information about lists, sets and other collections in the Collections trail of The Java Tutorials.
 
techin to
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jesper. I'm starting to understand it a little better now.
What I'm still fuzzy on is how to create a sublist, then retrieve from it.

So right now I have an arraylist like this.

public class MySubList
{

public static void main(String[] args)
{

ArrayList<Integer> data_set = new ArrayList<Integer>();

data_set.add(5); data_set.add(9); data_set.add(32); data_set.add(8); data_set.add(7); data_set.add(30);

}
}

But how can I create a list with sublist then print that sublist? Thanks.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just read the documentation. I'm sure that you'll figure it out. Please UseCodeTags when posting code. It makes it so much easier to read and will probably increase the number of people helping you.
 
techin to
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Read the documentation" - I have but there were no examples. Just the method name and description.

"Please use code tags" - will do.
 
techin to
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont understand the point of having a forum when you ask a question and sometimes tells you to read the documentation.
Obviously a person asking a question on a forum is confused about the material he has read and needs better clarification of the concept.

 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

techin to wrote:I dont understand the point of having a forum when you ask a question and sometimes tells you to read the documentation.
Obviously a person asking a question on a forum is confused about the material he has read and needs better clarification of the concept.



Ok champion, no need to get mad! Now, I've seen people here asking very basic things... so they obviously hadn't seen any documentation. So not everybody has the same attitude... not everybody reads before asking a question. It's just that what we try to do is encourage people to have a self-taught attitude... please don't get anybody wrong here!
 
techin to
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wasnt mad. I just wanted some help thats all whether it be considered a on basic question or not.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

techin to wrote:But how can I create a list with sublist then print that sublist? Thanks.


In the API reference documentation you can find all the standard Java classes, and see what methods are available on all the classes. If you lookup the class ArrayList (in package java.util), you will find that it has a method called subList (inherited from interface List). Click through to the documentation of interface List and you'll find the description of the subList method, which explains exactly how to use it (what arguments to pass, and what it returns).
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper Young wrote: . . . In the API reference documentation you can find . . . a method called subList . . .

I thought the documentation for subList was very clear and told me everything I would need to know.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

techin to wrote:I dont understand the point of having a forum when you ask a question and sometimes tells you to read the documentation.
Obviously a person asking a question on a forum is confused about the material he has read and needs better clarification of the concept.


Unfortunately a lot of people don't read the documentation. I've used subList before and I know that the documentation will tell you every thing you need to know. That's why I gave you that link. SubList is not a difficult method. So the documentation should be sufficient.
reply
    Bookmark Topic Watch Topic
  • New Topic