FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programs-1/collection/Map/TreeMapExample.java at master · Lalitha937/Java-Programs-1 · GitHub
Lalitha937
/
Java-Programs-1
Public
forked from
divScorp/Java-Programs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Programs-1
/
collection
/
Map
/
TreeMapExample.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (31 loc) · 864 Bytes
Breadcrumbs
Java-Programs-1
/
collection
/
Map
/
TreeMapExample.java
Copy path
File metadata and controls
32 lines (31 loc) · 864 Bytes
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
package
collection
.
Map
;
import
java
.
util
.
Map
;
import
java
.
util
.
TreeMap
;
/*
Value Associated with key 'two'= 2
Keysets: [one, seven, six, two]
Entry of map: [one=1, seven=7, six=6, two=2]
Size of map: 4
one : 1
{one=1, seven=7, six=6, two=2}
*/
public
class
TreeMapExample
{
public
static
void
main
(
String
[]
args
) {
Map
<
String
,
Integer
>
m
=
new
TreeMap
<>();
//Treemap sorts according to key
m
.
put
(
"six"
,
6
);
m
.
put
(
"one"
,
1
);
m
.
put
(
"two"
,
2
);
m
.
put
(
"seven"
,
7
);
System
.
out
.
print
(
"Value Associated with key 'two'= "
+
m
.
get
(
"two"
)+
"
\n
"
);
System
.
out
.
print
(
"Keysets: "
+
m
.
keySet
()+
"
\n
"
);
System
.
out
.
print
(
"Entry of map: "
+
m
.
entrySet
()+
"
\n
"
);
System
.
out
.
println
(
"Size of map: "
+
m
.
size
());
if
(
m
.
containsKey
(
"one"
)) {
Integer
x
=
m
.
get
(
"one"
);
System
.
out
.
println
(
"one : "
+
x
);
}
if
(!
m
.
isEmpty
())
System
.
out
.
println
(
m
);
}
}
Back
|
FazBrowse Home
|
New Git URL