aspose file tools*
The moose likes Java in General and the fly likes Help understanding how sublist works Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Help understanding how sublist works" Watch "Help understanding how sublist works" New topic
Author

Help understanding how sublist works

techin to
Greenhorn

Joined: Sep 30, 2010
Posts: 5
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.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14272
    
  21

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
techin to
Greenhorn

Joined: Sep 30, 2010
Posts: 5
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.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
techin to
Greenhorn

Joined: Sep 30, 2010
Posts: 5
"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

Joined: Sep 30, 2010
Posts: 5
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.

Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2266
    
    3

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!


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
techin to
Greenhorn

Joined: Sep 30, 2010
Posts: 5
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14272
    
  21

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).
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
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
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help understanding how sublist works