Skip to content

Commit 367278e

Browse files
committed
Adding more code files 07/10/25
1 parent c36f741 commit 367278e

4 files changed

Lines changed: 120 additions & 0 deletions

File tree

Array_List.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.util.ArrayList;
2+
import java.util.Collection;
3+
4+
public class Array_List
5+
{
6+
public static void main(String[] args)
7+
{
8+
Collection<Integer> nums=new ArrayList<Integer>();
9+
10+
nums.add(20); //Adding the data values
11+
nums.add(40);
12+
nums.add(70);
13+
14+
System.out.println(nums); //Printing the ArrayList
15+
16+
17+
}
18+
19+
}

Runnable_Demo.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
class A implements Runnable
2+
{
3+
public void run()
4+
{
5+
for(int i=0; i<20; i++)
6+
{
7+
System.out.println("Hi");
8+
9+
try
10+
{
11+
Thread.sleep(10);
12+
}
13+
catch(InterruptedException e)
14+
{
15+
System.out.println(e);
16+
}
17+
}
18+
}
19+
}
20+
21+
class B implements Runnable
22+
{
23+
public void run()
24+
{
25+
for(int i=0; i<20; i++)
26+
{
27+
System.out.println("Hello");
28+
29+
try
30+
{
31+
Thread.sleep(10);
32+
}
33+
catch(InterruptedException e)
34+
{
35+
System.out.println(e);
36+
}
37+
}
38+
}
39+
}
40+
41+
public class Runnable_Demo
42+
{
43+
public static void main(String[] args)
44+
{
45+
Runnable obj1=new A();
46+
47+
Runnable obj2=new B();
48+
49+
Thread t1=new Thread(obj1);
50+
51+
Thread t2=new Thread(obj2);
52+
53+
t1.start();
54+
55+
t2.start();
56+
}
57+
}

Runnable_Lambda.class

1.47 KB
Binary file not shown.

Runnable_Lambda.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//Implementation of Runnable Imterface using Lambda function
2+
3+
public class Runnable_Lambda
4+
{
5+
public static void main(String[] args) {
6+
{
7+
Runnable obj1=()-> //Lambda Function 01
8+
{
9+
for(int i=0; i<20; i++)
10+
{
11+
System.out.println("Hi");
12+
13+
try {
14+
Thread.sleep(10);
15+
} catch (InterruptedException e) {
16+
System.out.println(e);
17+
}
18+
}
19+
};
20+
21+
Runnable obj2= ()-> //Lambda function 02
22+
{
23+
for(int i=0; i<20; i++)
24+
{
25+
System.out.println("Hello");
26+
27+
try {
28+
Thread.sleep(10);
29+
} catch (InterruptedException e) {
30+
System.out.println(e);
31+
}
32+
}
33+
};
34+
35+
Thread t1=new Thread(obj1);
36+
37+
Thread t2=new Thread(obj2);
38+
39+
t1.start();
40+
41+
t2.start();
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)