Skip to content

Commit

Permalink
Chars in String
Browse files Browse the repository at this point in the history
  • Loading branch information
przemyslawkrawczynski committed Nov 22, 2019
1 parent 1faff3c commit f7643da
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 1 deletion.
Binary file modified .gradle/5.2.1/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/5.2.1/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/5.2.1/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/5.2.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/5.2.1/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified .gradle/5.2.1/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Expand Up @@ -8,7 +8,7 @@ public class ArrayInArrayCompareMain {
public static void main(String[] args) {

int[] a1 = {1, 4, 6, 3, 7, 9, 1, 4};
int[] a2 = {1, 4};
int[] a2 = {1, 4, 6};

IntsService intsService = new IntsService();

Expand Down
@@ -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." );
}
}
}
13 changes: 13 additions & 0 deletions src/main/java/pl/pk/algorithms/patterns/PatternsMain.java
@@ -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));
}
}
@@ -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);
}

}

0 comments on commit f7643da

Please sign in to comment.