Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created arraylist.java #738

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Java/arraylist.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import java.util.ArrayList;
import java.util.Collections;
public class arraylist{
public static void main(String args[]){
// declaring an array list..
ArrayList<Integer> list= new ArrayList<Integer>();
// adding elements to arraylist..
list.add(0);
list.add(6);
list.add(7);
// printing the arraylist;
System.out.println(list);
//getting the element;
int element= list.get(0);
System.out.println(element);
//add element in between..
list.add(1,1);
System.out.println(list);
//setting element or modifying array list
list.set(0,9);
System.out.println(list);
// removing the elements from array list;
list.remove(1);
System.out.println(list);
//getting the size;
System.out.println(list.size());

//loops
for(int i=0;i<list.size();i++){
System.out.println(" elements of arraylist" + list.get(i));
}

Collections.sort(list);
System.out.println(list);
}
}