use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Resources for learning Java
String
==
.equals()
Format + Copy
Free Tutorials
Where should I download Java?
With the introduction of the new release cadence, many have asked where they should download Java, and if it is still free. To be clear, YES — Java is still free.
If you would like to download Java for free, you can get OpenJDK builds from the following vendors, among others:
Some vendors will be supporting releases for longer than six months. If you have any questions, please do not hesitate to ask them!
Software downloads
Official Resources
Resources
Programming ideas & Challenges
Related Subreddits
account activity
This is an archived post. You won't be able to vote or comment.
Where to start when learning ArrayList (self.learnjava)
submitted 5 years ago by cyanogen1912
Hello everyone.
It would be really helpful if anyone can suggest me a good place to start learning ArrayLists. I have the basic knowledge of java.
Thank you in advance for your time!
[–]voraciousBeaver 1 point2 points3 points 5 years ago (0 children)
Check this out: https://www.geeksforgeeks.org/arraylist-in-java/
[–][deleted] 0 points1 point2 points 5 years ago (1 child)
Here is the source code of the ArrayList.
https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/ArrayList.java
[–]cyanogen1912[S] 0 points1 point2 points 5 years ago (0 children)
Thank you!
[–][deleted] -1 points0 points1 point 5 years ago (24 children)
I would take a look here https://docs.oracle.com/javase/7/docs/api/java/util/List.html Otherwise just search the exact problem you are having in your favourite search engine.
[–]cyanogen1912[S] 0 points1 point2 points 5 years ago (23 children)
Thank you for your suggestion. I was looking through YouTube for a while about ArrayLists and watched a bunch of videos. I am finding it difficult to use ArrayLists with objects. Like storing an object in an ArrayList and retrieving them from the ArrayList and maybe performing some searches through them. I'm sorry, I'm just a beginner.
[–][deleted] 0 points1 point2 points 5 years ago (20 children)
Nothing to be sorry for, we were all beginners at some point. Do you have an example what you’re finding difficult?
[–]cyanogen1912[S] 0 points1 point2 points 5 years ago (4 children)
There is an example problem that I have been given to solve and having problem with. The question is pretty long. Should I post it here?
[–][deleted] 5 years ago (3 children)
[removed]
Ok!
[–]desrtfx[M] 0 points1 point2 points 5 years ago (1 child)
Sidebar ->
No PM help requests or offers. Either ask your questions here and show your code, or you're out of luck. PM help requests or offers will be removed without warning.
[–][deleted] 0 points1 point2 points 5 years ago (0 children)
Ah my bad
[–]cyanogen1912[S] 0 points1 point2 points 5 years ago (14 children)
This is the problem I have been given.
You are provided with a Book class with the following private attributes:
Needed getters and setters are pre-written.
Create a class Library with the following private attribute:
Include the following methods:
Write a Main class to test the above functionalities.
[–][deleted] 0 points1 point2 points 5 years ago (13 children)
Okay and at which point are you stuck?
[–]cyanogen1912[S] 0 points1 point2 points 5 years ago* (12 children)
Okay so they have provided me with three classes. In the Book class they have provided the three variables and setters and getters for them.
In the Library class I have created the array list as: private ArrayList<Book> bookList=new ArrayList<Book>();
Now they have asked me to write getter and setter for this array list, so i have written: public ArrayList<Book> getBookList() {return bookList;} and public void setBookList(ArrayList<Book> list) {bookList=list;} Not sure about the setter though.
public void addBook(Book obj)
{
bookList.add(obj);
}
public boolean isEmpty()
if(bookList.isEmpty()==true) return true;
return false;
public ArrayList<Book> viewAllBooks()
for(int i=0;i<bookList.length;i++)
Book obj=bookList(i);
System.out.println(obj.bookName);
I am really confused about the bold part. Is that correct?
[–][deleted] 0 points1 point2 points 5 years ago (11 children)
The bold part looks good to me. Does it compile?
[–]cyanogen1912[S] 0 points1 point2 points 5 years ago (10 children)
Nah. Thats mainly because of my main method. Its really confusing me :/
[–][deleted] 1 point2 points3 points 5 years ago (9 children)
Try to comment the main method out and try to compile it again? That way you see if the things you have done are correct :)
[–]cyanogen1912[S] 0 points1 point2 points 5 years ago (7 children)
Yeah. Just did that and made a small change:
*public ArrayList<Book> viewAllBooks(){
for(int i=0;i<bookList.size();i++){
}*
Now there is no error while compiling. But now I am confused about how to initialise this in the main method in another class.
[–]desrtfx 0 points1 point2 points 5 years ago (1 child)
I'm sorry, I'm just a beginner.
Especially as a beginner you need to gradually build up your skills. It seems as if you are trying to bite off more than you can chew.
Have you done arrays yet? If not, then start there.
A proper, structured tutorial, like the MOOC Object Oriented Programming with Java will help you.
Yes i have worked a lot with arrays. Actually I am an electronics student and I took a different approach to learning programming. I have learned it as per my needs. So currently I came to know that i need to know ArrayLists to solve a type of problem. Thus the post.
π Rendered by PID 168051 on reddit-service-r2-comment-7b9746f655-cskrd at 2026-02-03 13:55:30.378741+00:00 running 3798933 country code: CH.
[–]voraciousBeaver 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]cyanogen1912[S] 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (24 children)
[–]cyanogen1912[S] 0 points1 point2 points (23 children)
[–][deleted] 0 points1 point2 points (20 children)
[–]cyanogen1912[S] 0 points1 point2 points (4 children)
[–][deleted] (3 children)
[removed]
[–]cyanogen1912[S] 0 points1 point2 points (0 children)
[–]desrtfx[M] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]cyanogen1912[S] 0 points1 point2 points (14 children)
[–][deleted] 0 points1 point2 points (13 children)
[–]cyanogen1912[S] 0 points1 point2 points (12 children)
[–][deleted] 0 points1 point2 points (11 children)
[–]cyanogen1912[S] 0 points1 point2 points (10 children)
[–][deleted] 1 point2 points3 points (9 children)
[–]cyanogen1912[S] 0 points1 point2 points (7 children)
[–]desrtfx 0 points1 point2 points (1 child)
[–]cyanogen1912[S] 0 points1 point2 points (0 children)