File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments