Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 23d44f1

Browse files
Codes of Module 9 added
1 parent 96412d5 commit 23d44f1

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

‎Module 9/Ex1.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
/**
8+
*
9+
* @author chandrikadeb
10+
*/
11+
import java.util.*;
12+
import java.util.stream.*;
13+
public class Ex1
14+
{
15+
public static void main(String[] args)
16+
{
17+
Stream<String> names = Stream.of("aBc", "d", "ef");
18+
System.out.println(names.map(s -> { return s.toUpperCase(); }).collect(Collectors.toList()));
19+
}
20+
21+
}

‎Module 9/Ex2.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
/**
8+
*
9+
* @author chandrikadeb
10+
*/
11+
import java.util.*;
12+
public class Ex2 {
13+
public static void main(String args[]) {
14+
System.out.println("Empty String Program: ");
15+
16+
// Count empty strings
17+
List<String> strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");
18+
System.out.println("List: " +strings);
19+
long count = getCountEmptyString(strings);
20+
21+
System.out.println("Empty Strings: " + count);
22+
23+
//Eliminate empty string
24+
List<String> filtered = deleteEmptyStrings(strings);
25+
System.out.println("Filtered List: " + filtered);
26+
27+
//Eliminate empty string and join using comma.
28+
String mergedString = getMergedString(strings,", ");
29+
System.out.println("Merged String: " + mergedString);
30+
}
31+
32+
private static int getCountEmptyString(List<String> strings) {
33+
int count = 0;
34+
35+
for(String string: strings) {
36+
37+
if(string.isEmpty()) {
38+
count++;
39+
}
40+
}
41+
return count;
42+
}
43+
44+
private static List<String> deleteEmptyStrings(List<String> strings) {
45+
List<String> filteredList = new ArrayList<String>();
46+
47+
for(String string: strings) {
48+
49+
if(!string.isEmpty()) {
50+
filteredList.add(string);
51+
}
52+
}
53+
return filteredList;
54+
}
55+
56+
private static String getMergedString(List<String> strings, String separator) {
57+
StringBuilder stringBuilder = new StringBuilder();
58+
59+
for(String string: strings) {
60+
61+
if(!string.isEmpty()) {
62+
stringBuilder.append(string);
63+
stringBuilder.append(separator);
64+
}
65+
}
66+
String mergedString = stringBuilder.toString();
67+
return mergedString.substring(0, mergedString.length()-2);
68+
}
69+
}
70+

‎Module 9/Ex3.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
/**
8+
*
9+
* @author chandrikadeb
10+
*/
11+
import java.util.*;
12+
public class Ex3
13+
{
14+
public static void main(String[] args)
15+
{
16+
System.out.println("Finding letter 'A' Program: ");
17+
List<String> members=Arrays.asList("Abish", "Bhargavi", "Alex", "Max", "Annie");
18+
System.out.println("List: " +members);
19+
20+
int count = getCount(members);
21+
System.out.println("Strings starting with 'A': " +count);
22+
}
23+
private static int getCount(List<String> members)
24+
{
25+
int count = 0;
26+
27+
for(String string: members) {
28+
29+
if(string.charAt(0)=='A') {
30+
count++;
31+
}
32+
}
33+
return count;
34+
}
35+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /