Commit a9bc1811 authored by Bhanuchander Pathuri's avatar Bhanuchander Pathuri

Java 8 and streams with practial examples

parent 7e3e2583
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Sample.iml" filepath="$PROJECT_DIR$/Sample.iml" />
</modules>
</component>
</project>
\ 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="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
import java.util.List;
public class Employee {
public Integer getId() {
return id;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Override
public String toString() {
return "Employee{" +
"id=" + id +
", name='" + name + '\'' +
", lastName='" + lastName + '\'' +
", phoneNumbers=" + phoneNumbers +
", age=" + age +
", dep='" + dep + '\'' +
", sal=" + sal +
'}';
}
public void setId(Integer id) {
this.id = id;
}
private Integer id;
private String name;
private String lastName;
public List<Long> getPhoneNumbers() {
return phoneNumbers;
}
public void setPhoneNumbers(List<Long> phoneNumbers) {
this.phoneNumbers = phoneNumbers;
}
private List<Long> phoneNumbers;
public Employee(Integer id, String name, String lastName, List<Long> phoneNumbers, Integer age, String dep, Double sal) {
this.id = id;
this.name = name;
this.lastName = lastName;
this.phoneNumbers = phoneNumbers;
this.age = age;
this.dep = dep;
this.sal = sal;
}
private Integer age;
private String dep;
private Double sal;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getDep() {
return dep;
}
public void setDep(String dep) {
this.dep = dep;
}
public Double getSal() {
return sal;
}
public void setSal(Double sal) {
this.sal = sal;
}
}
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Function;
import java.util.stream.Collectors;
class test1 extends Thread{
@Override
public void run() {
System.out.println("in run method running.........");
}
}
class test2 extends test1{
}
public class Flux {
public static void main(String[] args) {
String str1="Scaler";
System.out.println(str1.hashCode());
str1 = str1.concat("avc");
System.out.println(str1.hashCode());
String str2="Scaler";
System.out.println(str2.hashCode());
String str3=new String("Scaler");
System.out.println(str1==str2);
//true because both points to same memory allocation
System.out.println(str1==str3);
//false because str3 refers to instance created in heap
System.out.println(str1.equals(str3));
System.out.println(str1.substring(4));
}
}
\ No newline at end of file
This diff is collapsed.
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