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
1faff3c
commit f7643da
Showing
15 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+5 Bytes
(100%)
build/classes/java/main/pl/pk/algorithms/arrays/arrayInArray/ArrayInArrayCompareMain.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+1.24 KB
build/classes/java/main/pl/pk/algorithms/patterns/SingletonImplementation.class
Binary file not shown.
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
30 changes: 30 additions & 0 deletions
30
src/main/java/pl/pk/algorithms/numbers/charInString/HowManyTimeCharInString.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,30 @@ | ||
package pl.pk.algorithms.numbers.charInString; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class HowManyTimeCharInString { | ||
|
||
public static void main(String[] args) { | ||
|
||
String text = "abcdaabcd"; | ||
HashMap<String, Integer> resultMap = new HashMap<>(); | ||
|
||
for (int i = 0; i < text.length(); i++) { | ||
char l = text.charAt(i); | ||
String l2 = Character.toString(l); | ||
|
||
if (resultMap.containsKey(l2)) { | ||
int x = resultMap.get(l2); | ||
x = x + 1; | ||
resultMap.put(l2, x); | ||
} else { | ||
resultMap.put(l2, 1); | ||
} | ||
} | ||
|
||
for (Map.Entry<String, Integer> entry: resultMap.entrySet()) { | ||
System.out.println("Znak [" + entry.getKey() + "] is [" + entry.getValue() + "] times." ); | ||
} | ||
} | ||
} |
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,13 @@ | ||
package pl.pk.algorithms.patterns; | ||
|
||
public class PatternsMain { | ||
|
||
public static void main(String[] args) { | ||
|
||
SingletonImplementation singleton = SingletonImplementation.getINSTANCE(); | ||
SingletonImplementation singletonImplementation2 = SingletonImplementation.getINSTANCE(); | ||
|
||
singleton.showDesc(); | ||
System.out.println("It`s the same object? " + singleton.equals(singletonImplementation2)); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/pl/pk/algorithms/patterns/SingletonImplementation.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,30 @@ | ||
package pl.pk.algorithms.patterns; | ||
|
||
import java.util.Random; | ||
|
||
public class SingletonImplementation { | ||
|
||
private final String desc; | ||
private static SingletonImplementation INSTANCE = null; | ||
|
||
private SingletonImplementation() { | ||
Random r = new Random(); | ||
this.desc = r.nextInt(1256) + ""; | ||
} | ||
|
||
public static SingletonImplementation getINSTANCE() { | ||
if (INSTANCE == null) { | ||
synchronized (SingletonImplementation.class) { | ||
if (INSTANCE == null) { | ||
INSTANCE = new SingletonImplementation(); | ||
} | ||
} | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
public void showDesc() { | ||
System.out.println(desc); | ||
} | ||
|
||
} |