-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5746a43
commit 4b6a4b9
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
DesignPattern/src/com/akash/singletonforThread/RunnerThreadEnviroment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.akash.singletonforThread; | ||
|
||
public class RunnerThreadEnviroment { | ||
|
||
public static void main(String[] args) { | ||
// TODO | ||
|
||
/* Calling the thread singleton */ | ||
|
||
SingletonThreadEnviroment singleton = SingletonThreadEnviroment.getInstance(); | ||
|
||
System.out.println(singleton); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
DesignPattern/src/com/akash/singletonforThread/SingletonThreadEnviroment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.akash.singletonforThread; | ||
|
||
public class SingletonThreadEnviroment { | ||
|
||
private static volatile SingletonThreadEnviroment singletonInstance = null; | ||
|
||
private SingletonThreadEnviroment() {} | ||
|
||
public static SingletonThreadEnviroment getInstance() { | ||
if(singletonInstance == null) { | ||
synchronized(SingletonThreadEnviroment.class) { | ||
if(singletonInstance == null) { | ||
singletonInstance = new SingletonThreadEnviroment(); | ||
} | ||
} | ||
} | ||
return singletonInstance; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
Program/src/com/akash/latestProgram/NonRepeatCharFromString.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.akash.latestProgram; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class NonRepeatCharFromString { | ||
|
||
public static void main(String[] args) { | ||
firstNonRepeatedChar(); | ||
nonRepeatedChar(); | ||
} | ||
|
||
private static void nonRepeatedChar() { | ||
// TODO | ||
|
||
String str = "akashkumar"; | ||
|
||
HashMap<Character, Integer> map = new HashMap<>(); | ||
|
||
for(int i = 0; i<str.length(); i++) { | ||
|
||
char ch = str.charAt(i); | ||
|
||
if(map.containsKey(ch)) { | ||
int count = map.get(ch); | ||
map.put(ch, count+1); | ||
|
||
}else { | ||
map.put(ch, 1); | ||
} | ||
} | ||
|
||
for(Map.Entry<Character, Integer> entry : map.entrySet()) { | ||
if(entry.getValue()!= 1) | ||
System.out.print(entry.getKey()+""); | ||
} | ||
} | ||
|
||
private static void firstNonRepeatedChar() { | ||
// TODO | ||
String s = "java"; | ||
for(Character ch:s.toCharArray()) { | ||
if(s.indexOf(ch) == s.lastIndexOf(ch)) { | ||
System.out.println("First non repeat character = " + ch); | ||
break; | ||
} | ||
} | ||
} | ||
} |