Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
Core Java and Java 8
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
Lokesh Singh
Core Java and Java 8
Commits
4f35adba
Unverified
Commit
4f35adba
authored
Sep 28, 2022
by
Lokesh Singh
Committed by
GitHub
Sep 28, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add files via upload
parent
e3d36f99
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
333 additions
and
0 deletions
+333
-0
Collections-in-java.iml
Collections-in-java/Collections-in-java.iml
+11
-0
ListInJava.java
Collections-in-java/src/ListInJava.java
+18
-0
PrintElementsofArrayList.java
...va/src/com/lokesh/arraylist/PrintElementsofArrayList.java
+54
-0
HashSetInJava.java
...ections-in-java/src/com/lokesh/hashset/HashSetInJava.java
+40
-0
DiamondProblem.java
...ons-in-java/src/com/lokesh/interfaces/DiamondProblem.java
+31
-0
InterfaceTest.java
...ions-in-java/src/com/lokesh/interfaces/InterfaceTest.java
+51
-0
Example_Consumer.java
...tions-in-java/src/com/lokesh/lambda/Example_Consumer.java
+45
-0
Person.java
Collections-in-java/src/com/lokesh/model/Person.java
+5
-0
TreeSetInJava.java
...ections-in-java/src/com/lokesh/treeset/TreeSetInJava.java
+30
-0
Lambda-in-java.iml
Lambda-in-java/Lambda-in-java.iml
+11
-0
Main.java
Lambda-in-java/src/Main.java
+13
-0
Tread.iml
Thread-in-java/Tread.iml
+11
-0
Main.java
Thread-in-java/src/Main.java
+13
-0
No files found.
Collections-in-java/Collections-in-java.iml
0 → 100644
View file @
4f35adba
<?xml version="1.0" encoding="UTF-8"?>
<module
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
inherit-compiler-output=
"true"
>
<exclude-output
/>
<content
url=
"file://$MODULE_DIR$"
>
<sourceFolder
url=
"file://$MODULE_DIR$/src"
isTestSource=
"false"
/>
</content>
<orderEntry
type=
"jdk"
jdkName=
"openjdk-18"
jdkType=
"JavaSDK"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
\ No newline at end of file
Collections-in-java/src/ListInJava.java
0 → 100644
View file @
4f35adba
import
java.util.ArrayList
;
import
java.util.List
;
public
class
ListInJava
{
public
static
void
main
(
String
[]
args
)
{
List
strlist
=
new
ArrayList
<>();
//add at last
strlist
.
add
(
0
,
"0"
);
strlist
.
add
(
1
,
"1"
);
//replace
strlist
.
set
(
1
,
"3"
);
strlist
.
add
(
2
,
"2"
);
strlist
.
remove
(
0
);
strlist
.
forEach
(
System
.
out
::
println
);
}
}
\ No newline at end of file
Collections-in-java/src/com/lokesh/arraylist/PrintElementsofArrayList.java
0 → 100644
View file @
4f35adba
package
com
.
lokesh
.
arraylist
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
public
class
PrintElementsofArrayList
{
public
static
void
main
(
String
[]
args
)
{
ArrayList
<
String
>
strName
=
new
ArrayList
<>();
strName
.
add
(
"Lokesh"
);
strName
.
add
(
"babalu"
);
strName
.
add
(
"Nitin"
);
strName
.
add
(
"Naveen"
);
strName
.
add
(
"Lokesh"
);
// forEach loop
// for (String s : strName) {
// System.out.println(s);
// }
//access element in particular position
System
.
out
.
println
(
strName
.
get
(
2
));
//Lambda expression
// strName.forEach(System.out::println);
System
.
out
.
println
(
"\nAdd Name at 0th position"
);
strName
.
add
(
0
,
"milaan"
);
strName
.
forEach
(
System
.
out
::
println
);
System
.
out
.
println
(
"print arraylist\n"
);
System
.
out
.
println
(
strName
);
//Replace element at specific position
System
.
out
.
println
(
"\nlist after update the name:"
);
strName
.
set
(
2
,
"Ramesh"
);
System
.
out
.
println
(
strName
);
//Remove Element from list
System
.
out
.
println
(
"\nlist after remove ramesh"
);
strName
.
remove
(
2
);
System
.
out
.
println
(
strName
);
//Reverse Elements of list
System
.
out
.
println
(
"\nlist after reverse the list"
);
Collections
.
reverse
(
strName
);
System
.
out
.
println
(
strName
);
}
}
Collections-in-java/src/com/lokesh/hashset/HashSetInJava.java
0 → 100644
View file @
4f35adba
package
com
.
lokesh
.
hashset
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.TreeSet
;
public
class
HashSetInJava
{
public
static
void
main
(
String
[]
args
)
{
HashSet
<
Integer
>
set
=
new
HashSet
<>();
set
.
add
(
2
);
set
.
add
(
3
);
boolean
b1
=
set
.
add
(
2
);
set
.
add
(
4
);
set
.
add
(
1
);
Set
<
String
>
st
=
new
HashSet
<>();
st
.
add
(
"c"
);
st
.
add
(
"a"
);
st
.
add
(
"b"
);
st
.
forEach
((
n
)->
System
.
out
.
println
(
n
));
set
.
forEach
(
System
.
out
::
println
);
System
.
out
.
println
(
"See hashset also sort the data automatically\n"
);
System
.
out
.
println
(
set
);
System
.
out
.
println
(
"b1 = "
+
b1
+
"duplicate value"
);
System
.
out
.
println
(
"\nsize of set"
+
set
.
size
());
set
.
remove
(
1
);
System
.
out
.
println
(
set
);
System
.
out
.
println
(
set
.
isEmpty
());
TreeSet
<
Integer
>
tset
=
new
TreeSet
<
Integer
>(
set
);
System
.
out
.
println
(
tset
+
" This is treeset"
);
tset
.
ceiling
(
2
);
}
}
Collections-in-java/src/com/lokesh/interfaces/DiamondProblem.java
0 → 100644
View file @
4f35adba
package
com
.
lokesh
.
interfaces
;
public
class
DiamondProblem
{
public
static
void
main
(
String
[]
args
)
{
new
Toomuch
().
walk
();
}
}
class
Toomuch
implements
Father
,
Mother
{
/*
* When the interfaces that we are implementing has
* the same methods signatures then we must override them.
*/
@Override
public
void
walk
()
{
Father
.
super
.
walk
();
Mother
.
super
.
walk
();
System
.
out
.
println
(
"Walking like myself"
);
}
}
interface
Father
{
default
void
walk
()
{
System
.
out
.
println
(
"Walking like father"
);
}
}
interface
Mother
{
default
void
walk
()
{
System
.
out
.
println
(
"Walking like mother"
);
}
}
\ No newline at end of file
Collections-in-java/src/com/lokesh/interfaces/InterfaceTest.java
0 → 100644
View file @
4f35adba
package
com
.
lokesh
.
interfaces
;
public
class
InterfaceTest
implements
B
{
public
static
void
main
(
String
[]
args
)
{
new
InterfaceTest
().
go
();
}
public
void
go
()
{
concreteMethod
();
A
.
staticMethod
();
B
.
staticMethod
();
}
@Override
public
void
abstractMethod
()
{
System
.
out
.
println
(
"In class implemented method"
);
}
@Override
public
void
concreteMethod
()
{
B
.
super
.
concreteMethod
();
}
}
interface
A
{
void
abstractMethod
();
default
void
concreteMethod
()
{
System
.
out
.
println
(
"In interface A concrete method"
);
}
static
void
staticMethod
()
{
System
.
out
.
println
(
"in interface A concrete method"
);
}
}
interface
B
extends
A
{
default
void
concreteMethod
()
{
System
.
out
.
println
(
"In interface B concrete method"
);
}
static
void
staticMethod
()
{
System
.
out
.
println
(
"In interface B static method"
);
}
}
interface
C
{
default
void
concreteMethod
()
{
System
.
out
.
println
(
"In interface C concrete method"
);
}
}
Collections-in-java/src/com/lokesh/lambda/Example_Consumer.java
0 → 100644
View file @
4f35adba
package
com
.
lokesh
.
lambda
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.function.Consumer
;
public
abstract
class
Example_Consumer
{
public
static
void
main
(
String
[]
args
)
{
List
<
String
>
names
=
Arrays
.
asList
(
"Bruce"
,
"Logan"
,
"Peter"
);
System
.
out
.
println
(
"Using anonymous class"
);
names
.
forEach
(
new
Consumer
<
String
>()
{
@Override
public
void
accept
(
String
name
)
{
System
.
out
.
println
(
name
);
}
});
System
.
out
.
println
(
"\nUsing lambda expression"
);
names
.
forEach
(
name
->
System
.
out
.
println
(
name
));
System
.
out
.
println
(
"\nUsing method reference (will create a class on the fly)"
);
Consumer
<
String
>
myConsumer
=
System
.
out
::
println
;
names
.
forEach
(
System
.
out
::
println
);
System
.
out
.
println
(
"\nUsing stream to map to another class"
);
names
.
stream
().
map
(
Hero:
:
new
)
.
map
(
Hero:
:
getSecretIdentity
)
.
forEach
(
myConsumer
);
}
public
abstract
void
accept
(
String
name
);
}
class
Hero
{
private
String
secretIdentity
;
public
Hero
(
String
secretIdentity
)
{
this
.
secretIdentity
=
"Mr. "
+
secretIdentity
;
}
public
String
getSecretIdentity
()
{
return
secretIdentity
;
}
}
Collections-in-java/src/com/lokesh/model/Person.java
0 → 100644
View file @
4f35adba
package
com
.
lokesh
.
model
;
public
class
Person
{
}
Collections-in-java/src/com/lokesh/treeset/TreeSetInJava.java
0 → 100644
View file @
4f35adba
package
com
.
lokesh
.
treeset
;
import
java.util.Set
;
import
java.util.TreeSet
;
public
class
TreeSetInJava
{
public
static
void
main
(
String
[]
args
)
{
/**
* @Author Lokesh singh
* <p>
* TreeSet ts = new TreeSet();
* Set syncSet = Collections.synchronizedSet(ts);
*/
Set
<
String
>
tset
=
new
TreeSet
<>();
tset
.
add
(
"Mayukh"
);
tset
.
add
(
"Nikhil"
);
tset
.
add
(
"Lokesh"
);
tset
.
add
(
"Mohit"
);
tset
.
add
(
"Ravish"
);
tset
.
forEach
(
System
.
out
::
println
);
String
[]
str
=
tset
.
toArray
(
size
->
new
String
[
size
]);
// lambda expression
str
=
tset
.
toArray
(
size
->
new
String
[
size
*
10
]);
System
.
out
.
println
(
tset
.
toString
());
System
.
out
.
println
(
"treeset sort the data ascending order\n because its internal mechanism is sbst"
);
}
}
Lambda-in-java/Lambda-in-java.iml
0 → 100644
View file @
4f35adba
<?xml version="1.0" encoding="UTF-8"?>
<module
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
inherit-compiler-output=
"true"
>
<exclude-output
/>
<content
url=
"file://$MODULE_DIR$"
>
<sourceFolder
url=
"file://$MODULE_DIR$/src"
isTestSource=
"false"
/>
</content>
<orderEntry
type=
"jdk"
jdkName=
"openjdk-18"
jdkType=
"JavaSDK"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
\ No newline at end of file
Lambda-in-java/src/Main.java
0 → 100644
View file @
4f35adba
import
java.util.ArrayList
;
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
ArrayList
<
Integer
>
numbers
=
new
ArrayList
<>();
numbers
.
add
(
10
);
numbers
.
add
(
20
);
numbers
.
add
(
30
);
numbers
.
add
(
40
);
numbers
.
forEach
(
System
.
out
::
println
);
}
}
\ No newline at end of file
Thread-in-java/Tread.iml
0 → 100644
View file @
4f35adba
<?xml version="1.0" encoding="UTF-8"?>
<module
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
inherit-compiler-output=
"true"
>
<exclude-output
/>
<content
url=
"file://$MODULE_DIR$"
>
<sourceFolder
url=
"file://$MODULE_DIR$/src"
isTestSource=
"false"
/>
</content>
<orderEntry
type=
"jdk"
jdkName=
"openjdk-18"
jdkType=
"JavaSDK"
/>
<orderEntry
type=
"sourceFolder"
forTests=
"false"
/>
</component>
</module>
\ No newline at end of file
Thread-in-java/src/Main.java
0 → 100644
View file @
4f35adba
public
class
Main
implements
Runnable
{
public
void
run
()
{
System
.
out
.
println
(
"this code is running in thread"
);
}
public
static
void
main
(
String
[]
args
)
{
Main
obj
=
new
Main
();
Thread
thread
=
new
Thread
(
obj
);
thread
.
start
();
System
.
out
.
println
(
"this code is outside from the thread"
);
}
}
\ No newline at end of file
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