-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoxingExample.java
45 lines (30 loc) · 1.01 KB
/
BoxingExample.java
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
41
42
43
44
45
package boxing;
import java.util.*;
public class BoxingExample {
public static void main(String args[])
{
Integer i=new Integer(10); //Boxing
int j=i;//UnBoxing
System.out.println("Value of i: " + i);
System.out.println("Value of j: " + j);
Character ch='a';
char ch1=ch;
System.out.println("Value of ch: " + ch);
System.out.println("Value of ch1: " + ch1);
List<Integer> list = new ArrayList<Integer>();
for (int k = 0; k<=21; k++)
list.add(k);
int sumOdd = sumOfOddNumber(list);
System.out.println("Sum of odd numbers = " + sumOdd);
}
public static int sumOfOddNumber(List<Integer> list)
{
int sum = 0;
for (Integer i : list)
{
if(i % 2 != 0) //unboxing of i automatically
sum += i;
}
return sum;
}
}