2,130 questions
-1
votes
1
answer
98
views
How to Replace with StringBuilder from the right
I need to replace character sequences in a string, but they are not guaranteed not to be overlapping. The rule in case of conflicts is that ( first, the longest character sequence wins, but this is ...
4
votes
4
answers
264
views
Swap the first and the last words and reverse all the middle characters
Description
Guru gave a task to his students. He gave a sentence, and the students have to swap the first and the last words and reverse all the characters between those words. Help the students ...
-1
votes
3
answers
148
views
Joining Strings into final String when the items are in StringBuilder
I have read about the StringBuilder API and StringJoiner API and String.join but not sure if I have items in StringBuilder instance, which call to use to do a join with a delimiter of choice. I do not ...
2
votes
1
answer
141
views
How can I build a string that can pass null check but will throw null pointer exception when call str.length?
I met a quite strange case in a program with jdk1.8,
that I got a null pointer exception in String.length (which is in StringBuilder.append()) method,
the exact position of the null pointer exception ...
0
votes
1
answer
81
views
how the append method of StringBuilder in Java works, and why the string passed to it as a parameter doesn't create a new string object in memory
StringBuilder sb = new StringBuilder("mainWord");
sb.append("secondWord" + "thirdWord");
System.out.println(sb);
The append method here accepts a String as a parameter. ...
0
votes
1
answer
62
views
Tried to make a program that reconstructs numbers in string from a jumble string but got index out of bound error
Reconstruct Original Digits from English
Given a string s containing an out-of-order English representation of
digits 0-9, return the digits in ascending order.
I tried the code in Java but it ...
-1
votes
1
answer
382
views
StringBuilderPool Performance Benchmark Issue
In order to gain performance on the StringBuilder operations, I tried to apply the object pooling.
But pooling the StringBuilder seems to be slower than the original usage on both net8 and net7.
What ...
1
vote
2
answers
72
views
Issue converting stringBuilder + forloop to stream + map
What I am trying to achieve:
I would like to convert a StringBuilder + forloop, like this:
public String question(List<MyPojo> myPojos) {
final StringBuilder stringBuilder = new ...
0
votes
1
answer
248
views
Attaching a attachment to a calendar event using powershell
I am creating a calendar event using powershell. Ideally, I'd like to avoid using modules if possible because I feel like what I'm trying to do is very possible with what I have, but if a module is my ...
0
votes
3
answers
81
views
How to add all the elements of an int[] to a StringBuilder using a stream, adding extra space to each of the element
I am trying to add all the elements of an int array brr into a StringBuilder res using the following code:
StringBuilder res = new StringBuilder();
Arrays.stream(brr).forEach(res::append);
I want ...
-2
votes
1
answer
93
views
Is it worth the effort to empty a long string?
I used a StringBuilder to write an SQL query in .NET.
After I perform the query, is there a point in manually setting the contents of the string to ""?
I'm guessing this is already being ...
0
votes
0
answers
199
views
Why my StringBuilder.AppendLine method won't save non-english letters in C# .NET?
I am working on a school project and the task was to create an application, which one of the features is to save multi-lined text (user input) into a string. I know some parts of the code might be ...
0
votes
0
answers
48
views
Java Heap Error for StringBuilder while reading zips
I have a scenario to read zip files from a server URL. But I get a Java heap error when i append the string in the stringbuilder
public static void main(String args[]) {
String url = &...
0
votes
0
answers
49
views
im trying to send an email using an html file for structure. but its returning me the plain text
so im very new to programing and was tasked to send an email. the email gets sent. but it seems im either not using the html. or im rewriting or deleting it somehow. can someone give me a hand to ...
-2
votes
3
answers
217
views
How to format string in Java when the value goes from parameters? [duplicate]
I have a problem: I need to get a phone number as a string "79991111111" and convert it to this type of string "+7 (999) 111-11-11".
As i got it i'm able to do it by using a String....
-1
votes
1
answer
898
views
what is the most efficient way to clear an atomic reference to stringbuilder
If i have an AtomicReference to a StringBuilder defined as so:
private AtomicReference<StringBuilder> stringBuffer = new AtomicReference<>(new StringBuilder());
which method is best for ...
0
votes
2
answers
119
views
Trouble with String Builder: Filtering Characters in Java Swing JTextField
I'm fairly new to Java and stackoverflow.
Please alert me if I make a mistake or if I provide insufficient information.
I'm working on a Java Swing project and trying to use a custom DocumentFilter ...
0
votes
0
answers
64
views
why is this StringBuilder code not giving the desired output
I want to compress the string using StringBuilder but the code is not working as expected. It is simply returning the print statement.
import java.util.*;
public class string_compression {
public ...
0
votes
2
answers
528
views
Why does Java StringBuilder use 2147483639 as safe bound?
Java version: openjdk 11.0.19
When I was looking at the source code of StringBuilder, I noticed that it checks if the capacity exceeds 2147483639 when you use the append method.
I'm curious why this ...
0
votes
1
answer
1k
views
Using String.Join in String Builder C#
I am trying to create a csv string from a list of GUIDs (around 10000) of them. My snippet is below.
private string GetAppInformationForCache()
{
StringBuilder appInfo = new ();
var ...
0
votes
1
answer
79
views
Why is there a difference in memory address when using String Builder keyword in C#?
according to the theory after manupaliting string using String Builder keyword both memory address must be same, but i get wrong answer. could anyone please explain this.
class Program
{ ...
-2
votes
1
answer
278
views
What's the wrong with StringBuilder in code
class Solution {
public String mergeAlternately(String word1, String word2) {
int length = word1.length() + word2.length();
StringBuilder ans = new StringBuilder(length);
...
0
votes
4
answers
111
views
How can I do this but using StringBulider
I am trying to replicate this code using StringBuilder but can't figure out how.
What this does is check a given string (tweetText) with an array of Strings (usernames) and if is a match replaces the ...
-4
votes
2
answers
474
views
String append in java
I am constructing single string value based on some other string details, which is as below.
But don't wants to add if any of DTO value is null or empty. How can I add it in java.
String dummyVal = ...
0
votes
1
answer
108
views
Stringbuilder does not create new instance if the initial capacity set too small but a book says otherwise
StringBuilder sb = new StringBuilder("test", 4);
sb.Append('\n');
sb.AppendLine("test1");
sb.AppendLine("test2");
sb.AppendLine("test3");
sb.AppendLine("...