488 questions
0
votes
0
answers
43
views
ClassCastException is not coming in JDK21 in Eclipse
ClassCastException is not coming in JDK21 in Eclipse
I check whether I get a ClassCastException in the console by using the TreeSet<StringBuffer>. However, the values are sorted and the output ...
0
votes
1
answer
64
views
Flutter , stream letters to a single sentence
I'm getting a stream of words from server. The objective is to combine the words into a single sentence dynamically. Now what happens is as follows, the values are appended, but the entire string is ...
0
votes
0
answers
103
views
C++ multiple producer multiple consumer lock-free queue - where is my error?
I implemented the following multiple producer multiple consumer lock-free queue, however it crashes when I run it, inside dequeue function with "std::bad_alloc" exception. I don't understand ...
0
votes
3
answers
147
views
Replacing "is" with "is not" in Java
I'm in college and our professor gave us this exercise where the user should input a sentence such as "Life is great" (positiveInput in this case) and we should replace the word "is&...
0
votes
2
answers
129
views
Create a Java StringBuffer from a Map and Java Object
I am trying to create a csv file with the headers coming from a map and the values coming from an object. I have a Java object which stores different attribute data.
public class MyObject {
...
0
votes
0
answers
30
views
is there a way to std::basic_istream::get with a basic_streambuf to also read the delimeter char?
Given
#include<string>
#include<stringstream>
#include <fstream>
int main(int argc, char* args[])
{
std::fstream file("MyFile.txt", std::fstream::in);
std::stringbuf ...
0
votes
3
answers
37
views
shorter version of buffer write method (DRY)
I have this method and I want to know is there a practical and clean way to write this code shorter:
This excersice was from a Dart Apprentice: Beyond the Basics book.
void main() {
final lyric = '[...
0
votes
1
answer
56
views
Why does my rptr signal in vhdl move forward even tho it shouldn't?
Hi i have this block of code for a ring buffer
library ieee;
use ieee.std_logic_1164.all;
entity ring_buffer is
generic (
RAM_WIDTH : natural;
RAM_DEPTH : natural
);
port (
clk : ...
1
vote
1
answer
93
views
Not seeing full data in the string buffer in mutli thread logging
I am using ThreadLocal StringBuffer for storing entire log to move it to kibana at the end of each test case execution. But when I am running cases in parallel, the log is loosing some entries.
I am ...
-2
votes
1
answer
135
views
Write and Read file with RandomAccessFile in Java
Hello I am writing a program that write and read file XML in Java.
Here is the Writing file
public static void main(String[] args) throws IOException {
File file = new File("C:\\Test\\...
-2
votes
4
answers
144
views
Remove the last letter of every String in Array [JAVA] [closed]
As the title says.
In want to remove the last letter of every word in an array and put it to the beginning of every word.
Here's an example (Input):
Hello I am a player
And here's the output:
oHell I ...
-2
votes
3
answers
316
views
Reverse String inside a While Loop
I just started learning Java and I'm doing a little program to convert a decimal number into binary numbers using only while loops.
The results were reversed, therefore I'm using a method to reverse ...
0
votes
0
answers
399
views
Can we use String Buffer to store passwords in place of using char[] array?
It is preferred to use char[] to store passwords rather than a String in Java. But can we use StringBuffer instead of char[] to store passwords?
0
votes
1
answer
219
views
Java StringBuilder remove XML Tags
I'm trying to pass a XML object through a StringBuilder to compare to Objects, fitting to my needs.
I was wondering if there is a nice way to remove specific tags from the whole String. Underneath I ...
0
votes
1
answer
62
views
Why program did not show answer in out.txt?
The code should do a reverse and output the result to out.txt, but this does not happen, can you explain my mistake in the code. Thanks in advance
import java.io.BufferedReader;
import java.io....
0
votes
2
answers
657
views
Stringbuffer access by index or range
TLDR: I am looking for a datastructure with the properties of a string buffer that I can access by index in dart.
Long version: I need the properties of Stringbuffer (very efficient at adding ...
1
vote
2
answers
457
views
Remove blank lines in StringBuffer
After reading text file that contain words and numbers, I split it into words and numbers and left with blank lines in both splited words and numbers.
I try to remove the blank lines but the code did'...
-1
votes
2
answers
106
views
Why the following code use String and StringBuffer in the same line?
set.add(new String(s) + (ch == 0 ? "" : ch) + new StringBuffer(new String(s)).reverse());
I encountered this code from written by someone. It is java code.
s is a char[].
set is a String ...
-2
votes
1
answer
344
views
If else condition with StringBuffer
I'm trying to make a If else condition to check if a current data exists on the database using a JSON request on a java application consuming a Rest Webservice.
So, I want to receive a boolean or make ...
-1
votes
4
answers
1k
views
How to append String to StringBuffer variable in JAVA
My code is as below. i need to add single quotes for each word in string with single quotes after appending DD to it.
public class Main
{
public static void main(String[] args) {
String ...
-1
votes
3
answers
220
views
For a multi-threaded application why is it required to go for a synchronized implementation (if the requirement doesn't state that)
I have a very basic question. I have read that if we have a multi-threaded application then it is better to go with StringBuffer. But if we have a single thread application then it’s better to go with ...
-1
votes
1
answer
115
views
How to solve Java BufferString problem? I mean clearing buffer
I have little problem with my code, I split in Java String to table, then for I pick selected char and replace it with StringBuffer method.
The problem is when I use sout method at the end with ...
1
vote
0
answers
110
views
I can't make the case which String code compiled to StringBuffer code
1. Summarize the problem
I've heard String + operation will be changed when compiling after JDK 1.5.
But sadly I couldn't find the optimization case.
What did I miss? What did I do wrong?
2. Describe ...
-2
votes
1
answer
378
views
Interview Q: Reverse a word "Amazon" from string "I am working for Amazon"
I am able to reverse a string. For example, I can reverse "reverse a string" to "esrever a gnirts".
I am trying to create a function that reverse a word from a sentence. I only ...
1
vote
1
answer
54
views
what will happen when I use equals method to compare a string object and stringbuffer object?
What will happen when we compare String and Stringbuffer with the method equals?
String s1= "121";
System.out.println();
StringBuffer sb = new StringBuffer(s1);
sb.reverse();
System.out....
1
vote
0
answers
55
views
jdk1.8 StringBuffer source code method without synchronized keyword
@Override
public StringBuffer insert(int dstOffset, CharSequence s) {
// Note, synchronization achieved via invocations of other StringBuffer methods
// after narrowing of s to specific type
// ...
0
votes
2
answers
156
views
How do I save an array into string without all the data being mixed into a single line?
If I had an array that had store these data
String stringArray[] = {
"Apple a Day Keep You Away",
"Banana a Day Keep Her Away",
"Cat like Dog"};
...
1
vote
1
answer
4k
views
Is StringBuffer the Kotlin way to handle multiple string concatenation like in java?
What would be the kotlin way to handle multiple string concatenation?
--edit--
placing the piece of code that led me to this doubt
fun getNCharsFromRange(n: Int, range: CharRange): String {
val ...
0
votes
5
answers
979
views
string.concat(string) function, why my code is giving false in the output
String s1="Hello";
s1=s1.concat("World");
String s2="HelloWorld";
System.out.println(s1);
System.out.println(s2);
System.out.println(s2==s1); //false
As after ...
0
votes
4
answers
8k
views
How to replace specific String in a text file by java?
I'm writing a program with a text file in java, what I need to do is to modify the specific string in the file.
For example, the file has a line(the file contains many lines)like "username,...
0
votes
2
answers
529
views
How can I use Pattern and Matcher with StringBuffer or char[] types instead of String?
How can I use a method like this
private boolean respectPattern(String password) {
Pattern passwordPattern = Pattern.compile(
"^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[.@$!%*?&])[A-Za-z\\d@...
0
votes
1
answer
596
views
Java StringBuffer dynamically append Strings at certain offset
I have a String value which has a maximum length of 629 characters. i am using StringBuffer to insert values on specific offset index.
StringBuffer sb = new StringBuffer(" ...
0
votes
1
answer
114
views
Switch case doesn't print to the console?
public static void startGame(){
//int stone = 0, diamond = 0, iron = 0, gold = 0;
StringBuffer blockys = new StringBuffer("\uD83E\uDDCD ▯▯▯▯▯▯▯▯▯");
Scanner input = new Scanner(...
0
votes
0
answers
342
views
Generating user specified amount of random vowels/consonsants java
I am trying to make a program that will choose a random assortment of 9 letters where the user specifies how many each of consonants and vowels to select.
So far I have:
char consonants [] = {'b','c'...
0
votes
3
answers
299
views
StringBuffer vs normal print
Why printing the array items in a loop taking more time as compared to appending all array items into StringBuffer and then print?
In this, I printed array items in the loop.
public static void main ...
0
votes
0
answers
1k
views
How to handle huge json over network call through pagination in java?
I have this existing API running in loop which creates a connection and fetches huge json(1 GB) in each iteration from a service through restTemplate as follow:
ResponseEntity<String> response =...
2
votes
2
answers
643
views
what is the significance of StringBuffer and which should be used more often, StringBuffer or StringBuilder? [duplicate]
Why is StringBuffer needed in java? i am totally new to java, and was studying about operations on Strings and String methods when i saw another set of methods, which were similar somewhat similar, in ...
-1
votes
4
answers
1k
views
How to use stringBuilder
I have a function and Technical Leader review code and said :
Why this if statement? It's basically the same message. If you want customized, use a string builder with the type.
How to change it , can ...
1
vote
3
answers
1k
views
StringBuffer not giving ClassCastException when trying to add in a treeset without Comparator
I was expecting the ClassCastException when trying to run the following piece of code:
// TreeSet<StringBuffer> t = new TreeSet<StringBuffer>((a, b) -> -
// a.toString().compareTo(...
1
vote
1
answer
216
views
Replacing a specific Char from a String between two positions
Consider the following String:
String str = "XFB_PART~\XFB_IDF~\XFB_MODE~0\XFB_LOCALITEM~\XFB_REMOTEITEM~\XFB_MSG~tool\ soundgarden~\ASYNCHRONOUS~0\BROADCAST~0\XFB_LOCALAGT~"
What I would like to do ...
1
vote
2
answers
332
views
Extract only first occurrence of character and all the numbers before and after hyphen
I got into this situation to write a generic function which can extract only first occurrence of the character and all the number from a string.
Input String (Say): ABC123-45DEF-GH67IJ9
Output String:...
0
votes
2
answers
92
views
How does sb2 in the below code holds abc but not abcd?
StringBuffer sb1 = new StringBuffer("abc");
StringBuffer sb2 = new StringBuffer(sb1);
sb1.append("d");
System.out.println(sb2);
Since StringBuffer is mutable and sb2 points to sb1, i ...
0
votes
2
answers
289
views
how does stringbuffer/stringbuilder works in memory? how does the stringbuilder.delete function works?
I have appended some strBuild with some characters and putting that strBuild into stringBuildArr. then called the java.lang.StringBuilder.delete(int start, int end) function on strBuild.
Here is the ...
0
votes
0
answers
805
views
I have to make getArrayStringLongerThan()
I'm trying to make getArrayStringLongerThan() constructor that returns a StringBuffer array with COPIES of StringBuffer objects in the array parameter that have a length greater than the length ...
0
votes
2
answers
399
views
How to remove all occurrences of a substring from a string
I have a String(txt) and in this String is html code. I will search the String with txt.indexOf for
("< ac:structured-macro ac:macro-id=")
and delet it with StringBuffer(sb) sb.delete(Index, ...
-1
votes
1
answer
165
views
StringBuffer equal to string but not working
I'm trying to check the with an if-statement if two strings are the same(which they are), but it doesn't work. Here is my code and my first input value (https://i.sstatic.net/hEkr7.jpg) . In the ...
3
votes
2
answers
575
views
How hash code is generated for StringBuffer object in java? [duplicate]
I am studying String in java and while studying I came to know that hash code is generated for every string.
I want to know how hash code is generated in the case of StringBuffer.
0
votes
2
answers
2k
views
How to gets numbers from txt file and than parse to integer?
I use Android Studio.I have a text file with some of numbers and I want to calculate them with others numbers. When I am try to convert them from string with method Integer.parseInt on program start I ...
0
votes
1
answer
129
views
Use StringBuffer to replace substring throughout a long string
I need to compose a long string (4324 characters) and want to use StringBuffer for this purpose. Most of the string will be whitespace but some portions contain orderdetails. They must appear at ...
0
votes
1
answer
271
views
Dart class StringBuffer string.contains error
methods ‘contains’ not defined in class ‘stringbuffer’ compilation error is being generated from the following code:
import 'dart:math';
var now = new DateTime.now();
Random rnd = new Random();
...