Skip to content

Commit 98751f9

Browse files
committed
Merge branch 'master' of https://github.com/eugenp/tutorials
2 parents 2a84944 + b7aa6a2 commit 98751f9

62 files changed

Lines changed: 1359 additions & 1296 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎core-java-8/src/test/java/com/baeldung/streamordering/BenchmarkUnitTest.java‎

Lines changed: 0 additions & 97 deletions
This file was deleted.

‎core-java-8/src/test/java/com/baeldung/streamordering/StreamsOrderingUnitTest.java‎

Lines changed: 0 additions & 149 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
*
3+
*/
4+
package com.baeldung.string;
5+
6+
/**
7+
* @author swpraman
8+
*
9+
*/
10+
public class AppendCharAtPositionX {
11+
12+
public String addCharUsingCharArray(String str, char ch, int position) {
13+
validate(str, position);
14+
int len = str.length();
15+
char[] updatedArr = new char[len + 1];
16+
str.getChars(0, position, updatedArr, 0);
17+
updatedArr[position] = ch;
18+
str.getChars(position, len, updatedArr, position + 1);
19+
return new String(updatedArr);
20+
}
21+
22+
public String addCharUsingSubstring(String str, char ch, int position) {
23+
validate(str, position);
24+
return str.substring(0, position) + ch + str.substring(position);
25+
}
26+
27+
public String addCharUsingStringBuilder(String str, char ch, int position) {
28+
validate(str, position);
29+
StringBuilder sb = new StringBuilder(str);
30+
sb.insert(position, ch);
31+
return sb.toString();
32+
}
33+
34+
private void validate(String str, int position) {
35+
if (str == null) {
36+
throw new IllegalArgumentException("Str should not be null");
37+
}
38+
int len = str.length();
39+
if (position < 0 || position > len) {
40+
throw new IllegalArgumentException("position[" + position + "] should be "
41+
+ "in the range 0.." + len + " for string " + str);
42+
}
43+
}
44+
45+
}

‎core-java/src/test/java/com/baeldung/linesintersection/LinesIntersectionServiceUnitTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void givenNotParallelLines_whenCalculatePoint_thenPresent() {
2323

2424
assertTrue(point.isPresent());
2525
assertEquals(point.get().getX(), 1, 0.001);
26-
assertEquals(point.get().getX(), 1, 0.001);
26+
assertEquals(point.get().getY(), 0, 0.001);
2727
}
2828

2929
@Test

0 commit comments

Comments
 (0)