Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
132 views

Java 8 Stream Practice

The document provides code for classes TempStudent, Student, Address, and MobileNumber. It then lists 11 questions about performing operations on a List of TempStudent objects such as getting students by name or address, converting between different list types, sorting, and filtering.

Uploaded by

Shashwat Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
132 views

Java 8 Stream Practice

The document provides code for classes TempStudent, Student, Address, and MobileNumber. It then lists 11 questions about performing operations on a List of TempStudent objects such as getting students by name or address, converting between different list types, sorting, and filtering.

Uploaded by

Shashwat Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java 8 Stream Practice

By looking at below example class, answer the following questions,

1. Get student with exact match name "James"


2. Get student with matching address "1235"
3. Get all student having mobile numbers 3333.
4. Get all student having mobile number 1233 and 1234
5. Create a List<Student> from the List<TempStudent>
6. Convert List<Student> to List<String> of student name
7. Convert List<students> to String
8. Change the case of List<String>
9. Sort List<String>
10. Conditionally apply Filter condition, say if flag is enabled then.

11. class TempStudent {


12. public String name;
13. public int age;
14. public Address address;
15. public List<MobileNumber> mobileNumbers;
16.
17. public TempStudent(String name, int age, Address address,
List<MobileNumber> mobileNumbers) {
18. this.name = name;
19. this.age = age;
20. this.address = address;
21. this.mobileNumbers = mobileNumbers;
22. }
23. }
24.
25. class Student{
26. private String name;
27. private int age;
28. private Address address;
29. private List<MobileNumber> mobileNumbers;
30.
31. public Student(String name, int age, Address address,
List<MobileNumber> mobileNumbers) {
32. this.name = name;
33. this.age = age;
34. this.address = address;
35. this.mobileNumbers = mobileNumbers;
36. }
37.
38. public String getName() {
39. return name;
40. }
41.
42. public int getAge() {
43. return age;
44. }
45.
46. public Address getAddress() {
47. return address;
48. }
49.
50. public List<MobileNumber> getMobileNumbers() {
51. return mobileNumbers;
52. }
53.
54. public void setName(String name) {
55. this.name = name;
56. }
57.
58. public void setAge(int age) {
59. this.age = age;
60. }
61.
62. public void setAddress(Address address) {
63. this.address = address;
64. }
65.
66. public void setMobileNumbers(List<MobileNumber> mobileNumbers) {
67. this.mobileNumbers = mobileNumbers;
68. }
69.
70. @Override
71. public String toString() {
72. return "Student{" +
73. "name='" + name + '\'' +
74. ", age=" + age +
75. ", address=" + address +
76. ", mobileNumbers=" + mobileNumbers +
77. '}';
78. }
79. }
80.
81. class Address{
82. private String zipcode;
83.
84. public Address(String zipcode) {
85. this.zipcode = zipcode;
86. }
87.
88. public String getZipcode() {
89. return zipcode;
90. }
91.
92. public void setZipcode(String zipcode) {
93. this.zipcode = zipcode;
94. }
95. }
96.
97. class MobileNumber{
98. private String number;
99.
100. public MobileNumber(String number) {
101. this.number = number;
102. }
103.
104. public String getNumber() {
105. return number;
106. }
107.
108. public void setNumber(String number) {
109. this.number = number;
110. }
111. }

You might also like