Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
Java8Practies
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Uma Vani Ravuri
Java8Practies
Commits
db7753dd
Commit
db7753dd
authored
Sep 21, 2021
by
Uma Vani Ravuri
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
java8 code practies
parents
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
208 additions
and
0 deletions
+208
-0
.classpath
Java8PractiesProgram/.classpath
+10
-0
.project
Java8PractiesProgram/.project
+17
-0
org.eclipse.jdt.core.prefs
Java8PractiesProgram/.settings/org.eclipse.jdt.core.prefs
+12
-0
Employee.class
Java8PractiesProgram/bin/com/java8/practies/Employee.class
+0
-0
EmployeeComparator.class
...esProgram/bin/com/java8/practies/EmployeeComparator.class
+0
-0
TestEmployee.class
...PractiesProgram/bin/com/java8/practies/TestEmployee.class
+0
-0
Employee.java
Java8PractiesProgram/src/com/java8/practies/Employee.java
+71
-0
EmployeeComparator.java
...iesProgram/src/com/java8/practies/EmployeeComparator.java
+12
-0
TestEmployee.java
...8PractiesProgram/src/com/java8/practies/TestEmployee.java
+86
-0
No files found.
Java8PractiesProgram/.classpath
0 → 100644
View file @
db7753dd
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry
kind=
"con"
path=
"org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"
>
<attributes>
<attribute
name=
"module"
value=
"true"
/>
</attributes>
</classpathentry>
<classpathentry
kind=
"src"
path=
"src"
/>
<classpathentry
kind=
"output"
path=
"bin"
/>
</classpath>
Java8PractiesProgram/.project
0 → 100644
View file @
db7753dd
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>
Java8PractiesProgram
</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>
org.eclipse.jdt.core.javabuilder
</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>
org.eclipse.jdt.core.javanature
</nature>
</natures>
</projectDescription>
Java8PractiesProgram/.settings/org.eclipse.jdt.core.prefs
0 → 100644
View file @
db7753dd
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
Java8PractiesProgram/bin/com/java8/practies/Employee.class
0 → 100644
View file @
db7753dd
File added
Java8PractiesProgram/bin/com/java8/practies/EmployeeComparator.class
0 → 100644
View file @
db7753dd
File added
Java8PractiesProgram/bin/com/java8/practies/TestEmployee.class
0 → 100644
View file @
db7753dd
File added
Java8PractiesProgram/src/com/java8/practies/Employee.java
0 → 100644
View file @
db7753dd
package
com
.
java8
.
practies
;
import
java.util.Comparator
;
import
java.util.List
;
public
class
Employee
implements
Comparator
<
Employee
>{
String
id
;
String
firstName
;
String
lastName
;
String
departmentNames
;
public
Employee
()
{
super
();
// TODO Auto-generated constructor stub
}
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
public
String
getFirstName
()
{
return
firstName
;
}
public
void
setFirstName
(
String
firstName
)
{
this
.
firstName
=
firstName
;
}
public
String
getLastName
()
{
return
lastName
;
}
public
void
setLastName
(
String
lastName
)
{
this
.
lastName
=
lastName
;
}
public
String
getDepartmentNames
()
{
return
departmentNames
;
}
public
void
setDepartmentNames
(
String
departmentNames
)
{
this
.
departmentNames
=
departmentNames
;
}
public
Employee
(
String
id
,
String
firstName
,
String
lastName
,
String
departmentNames
)
{
super
();
this
.
id
=
id
;
this
.
firstName
=
firstName
;
this
.
lastName
=
lastName
;
this
.
departmentNames
=
departmentNames
;
}
@Override
public
String
toString
()
{
return
"Employee [id="
+
id
+
", firstName="
+
firstName
+
", lastName="
+
lastName
+
", departmentNames="
+
departmentNames
+
"]"
;
}
@Override
public
int
compare
(
Employee
o1
,
Employee
o2
)
{
// TODO Auto-generated method stub
return
o1
.
firstName
.
compareTo
(
o2
.
firstName
);
}
}
Java8PractiesProgram/src/com/java8/practies/EmployeeComparator.java
0 → 100644
View file @
db7753dd
package
com
.
java8
.
practies
;
import
java.util.Comparator
;
public
class
EmployeeComparator
implements
Comparator
<
Employee
>
{
@Override
public
int
compare
(
Employee
o1
,
Employee
o2
)
{
return
o1
.
getFirstName
().
compareTo
(
o2
.
getFirstName
());
}
}
Java8PractiesProgram/src/com/java8/practies/TestEmployee.java
0 → 100644
View file @
db7753dd
package
com
.
java8
.
practies
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
public
class
TestEmployee
{
public
static
void
main
(
String
[]
args
)
{
ArrayList
<
Employee
>
list
=
new
ArrayList
<
Employee
>();
list
.
add
(
new
Employee
(
"1"
,
"Uma"
,
"Vani"
,
"IT"
));
list
.
add
(
new
Employee
(
"2"
,
"Sujit"
,
"Krishnan"
,
"CSE"
));
list
.
add
(
new
Employee
(
"3"
,
"Brayan"
,
"Bra"
,
"IT"
));
list
.
add
(
new
Employee
(
"4"
,
"Allice"
,
"Ali"
,
"CSE"
));
list
.
add
(
new
Employee
(
"5"
,
"Sco te"
,
"Scote"
,
"IT"
));
list
.
add
(
new
Employee
(
"6"
,
"Rajesh"
,
"Krishnan"
,
"ECE"
));
list
.
add
(
new
Employee
(
"7"
,
"Ramana"
,
"Raju"
,
"IT"
));
list
.
add
(
new
Employee
(
"8"
,
"Raju"
,
"Krishnan"
,
"EEE"
));
list
.
add
(
new
Employee
(
"9"
,
"Rishi"
,
"Vani"
,
"IT"
));
list
.
add
(
new
Employee
(
"10"
,
"Dattu"
,
"Krishnan"
,
"EEE"
));
//1)list of employees, get the first employee from the list and return his fullName
list
.
stream
().
limit
(
1
)
.
forEach
(
x
->
System
.
out
.
println
(
"First employee Full Name is::"
+
x
.
firstName
+
x
.
lastName
));
//given a list of employees. Can you create a map with the count of employees each department has ?
//with key as department name and count of employees as value.
Map
<
String
,
Long
>
mapDepartment
=
list
.
stream
()
.
collect
(
Collectors
.
groupingBy
(
Employee:
:
getDepartmentNames
,
Collectors
.
counting
()));
mapDepartment
.
forEach
((
k
,
v
)
->
System
.
out
.
println
((
k
+
":"
+
v
)));
//Given a map with the department name as key and value as list of employees belonging to that department.
//when a search string is given, need to list out the employees whose firstname or lastname is matching(match should be case insensitive)
Map
<
String
,
List
<
Employee
>>
mapEmployee
=
list
.
stream
()
.
collect
(
Collectors
.
groupingBy
(
Employee:
:
getDepartmentNames
,
Collectors
.
toList
()));
mapEmployee
.
forEach
((
k
,
v
)
->
System
.
out
.
println
((
k
+
":"
+
v
)));
//Consider a list of employees, and if a department name is given as argument, list out the employees which doesn't belong to that department.
List
<
Employee
>
filterEmp
=
list
.
stream
().
filter
(
x
->
!
x
.
getDepartmentNames
().
equals
(
"IT"
))
.
collect
(
Collectors
.
toList
());
filterEmp
.
forEach
(
x
->
System
.
out
.
println
(
" Employee list whose Department is not IT"
+
x
));
// 6)Consider a list of employees, sort the employees by their firstName and
// return the sorted list of employees.
List
<
Employee
>
sortedEmployee
=
list
.
stream
().
sorted
(
new
EmployeeComparator
()).
collect
(
Collectors
.
toList
());
sortedEmployee
.
forEach
(
x
->
System
.
out
.
println
(
"Sorted Employee based on firstName"
+
x
));
//Consider a list of employees, return the employee whose empId is highest
Employee
e
=
list
.
stream
().
max
((
e1
,
e2
)
->
e1
.
getId
().
compareTo
(
e2
.
getId
())).
get
();
System
.
out
.
println
(
"Maximum Id Employee details"
+
e
);
//Consider a list of employees, concat the fullName of all the employees with pipe (|) and return the concatenated string.
String
joinedString
=
list
.
stream
().
map
(
x
->
x
.
firstName
+
x
.
lastName
).
collect
(
Collectors
.
joining
(
"|"
));
System
.
out
.
println
(
"Maximum Id Employee details-----------"
+
joinedString
);
//Consider a list of 10 employees, get the 8th employee and print his full name and department name.
list
.
stream
().
sorted
((
e1
,
e2
)
->
e1
.
getId
().
compareTo
(
e2
.
getId
())).
skip
(
8
).
limit
(
1
)
.
forEach
(
System
.
out
::
println
);
//consider list of employees and list of employee ids. return the list of employees matching with the given list of employee ids.
List
<
Employee
>
checkForMatches
=
new
ArrayList
<>();
checkForMatches
.
add
(
new
Employee
(
"2"
,
"siri"
,
"raja"
,
"CSE"
));
checkForMatches
.
add
(
new
Employee
(
"7"
,
"roja"
,
"rani"
,
"CSE"
));
checkForMatches
.
add
(
new
Employee
(
"11"
,
"roja"
,
"rani"
,
"CSE"
));
List
<
Employee
>
filteredList
=
list
.
stream
()
.
filter
(
employee
->
checkForMatches
.
stream
().
anyMatch
(
dept
->
employee
.
getId
().
equals
(
dept
.
getId
())))
.
collect
(
Collectors
.
toList
());
filteredList
.
forEach
(
x
->
System
.
out
.
println
(
"Employee matches"
+
x
));
//Store ids are of 4 digit strings.if length of given storeId is less than 4 digits,you need to prefix with zeros and return a 4 digit storeId.
list
.
stream
().
forEach
(
x
->
System
.
out
.
println
(
"4 Digits employee Id::"
+
String
.
format
(
"%04d"
,
Integer
.
parseInt
(
x
.
id
))));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment