Unverified Commit 4f35adba authored by Lokesh Singh's avatar Lokesh Singh Committed by GitHub

Add files via upload

parent e3d36f99
<?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
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
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);
}
}
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);
}
}
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
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");
}
}
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;
}
}
package com.lokesh.model;
public class Person {
}
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");
}
}
<?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
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
<?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
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment