FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
All-Java-Works/ArrayListPart1.java at master · shakiz/All-Java-Works · GitHub
shakiz
/
All-Java-Works
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
All-Java-Works
/
ArrayListPart1.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (31 loc) · 1.32 KB
Breadcrumbs
All-Java-Works
/
ArrayListPart1.java
Copy path
File metadata and controls
40 lines (31 loc) · 1.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
Characteristics in arraylist:
1.ArrayList inherits AbstractList class and implements List interface.
2.ArrayList is initialized by a size, however the size can increase if collection grows or shrunk if objects are removed from the collection.
3.Java ArrayList allows us to randomly access the list.
4.ArrayList can not be used for primitive types, like int, char, etc. We need a wrapper class for such cases (see this for details).
5.ArrayList in Java can be seen as similar to vector in C++.
*/
package
arraylist
.
part1
;
import
java
.
util
.
ArrayList
;
public
class
ArrayListPart1
{
public
static
void
main
(
String
[]
args
) {
// size of ArrayList
int
n
=
5
;
//declaring ArrayList with initial size n
ArrayList
<
Integer
>
arrli
=
new
ArrayList
<
Integer
>(
n
);
// Appending the new element at the end of the list
for
(
int
i
=
1
;
i
<=
n
;
i
++){
arrli
.
add
(
i
);
}
// Printing elements
System
.
out
.
println
(
arrli
);
// Remove element at index 3
arrli
.
remove
(
3
);
// Displaying ArrayList after deletion
System
.
out
.
println
(
arrli
);
// Printing elements one by one
for
(
int
i
=
0
;
i
<
arrli
.
size
();
i
++)
System
.
out
.
print
(
arrli
.
get
(
i
)+
" "
);
}
}
Back
|
FazBrowse Home
|
New Git URL