Linked Questions

3 votes
4 answers
4k views

In the past, I have been lead to believe that you should use StringBuilder and append(String) when building a string with variables, as opposed to string += split[i]. In what cases is this accurate? I ...
OllieStanley's user avatar
1127 votes
20 answers
519k views

Given the 2 toString() implementations below, which one is preferred: public String toString(){ return "{a:"+ a + ", b:" + b + ", c: " + c +"}"; } or public String toString(){ StringBuilder ...
non sequitor's user avatar
  • 18.9k
402 votes
9 answers
327k views

It is supposed to be generally preferable to use a StringBuilder for string concatenation in Java. Is this always the case? What I mean is this: Is the overhead of creating a StringBuilder object, ...
kostja's user avatar
  • 61.7k
85 votes
12 answers
50k views

Is there an easy way to print the contents of a Bundle to Logcat if you can't remember the names of all the keys (even being able to print just the key names would be cool)?
Quasaur's user avatar
  • 1,365
134 votes
7 answers
35k views

Why in Java you're able to add Strings with the + operator, when String is a class? In theString.java code I did not find any implementation for this operator. Does this concept violate object ...
Pooya's user avatar
  • 4,481
3 votes
4 answers
869 views

Possible Duplicate: java String concatenation StringBuilder vs String concatenation in toString() in Java I ve read some articles about append() is much faster than +, but what is the reason ,...
sammiwei's user avatar
  • 3,228
-1 votes
3 answers
6k views

I have the following code: private String foo; public void setFoo(String bar) { foo = bar + "bin/"; } I expect this code to concat bar and "bin/" using the overloaded '+' operator. And when I do ...
Grammin's user avatar
  • 12.3k
2 votes
2 answers
937 views

So everyone knows that the shortest Java program that you can write is: public class Program{ public static void main(String []args){ } } One would suspect that this shortest program would ...
Juru's user avatar
  • 1,639
1 vote
3 answers
573 views

I come across an error while running this in Java: // Test.java public class Test { public static void main(String [] args) throws IOException { String a = "123"; a = a + "456"; ...
Tianyi Hao's user avatar
1 vote
4 answers
175 views

StringBuffer sb = new StringBuffer(); sb.append("New "+"Delhi"); and other is: sb.append("New ").append("Delhi"); both will print "New Delhi". Which one is better and why? Because some times to ...
Abhishek Sharma's user avatar
0 votes
2 answers
202 views

I have to open a webview which loads a dynamic url based on certain parameters, I have to create the url based on different strings. What I'd like to do is the following: String webPage = "www....
user3909319's user avatar
0 votes
1 answer
221 views

I'm doing BFS search through the Wikipedia (spanish edition) site. I converted the dump (https://dumps.wikimedia.org/eswiki/20160601) into a file that could be read with Giraph. The BFS is searching ...
chomp's user avatar
  • 1,352
-1 votes
2 answers
97 views

I've got a question to my program: public class Muster2 { int[] farben; constructs an array with 4 integers public Muster2(int f0, int f1, int f2, int f3) { int[] farben = new int[4]; farben[0] = ...
rikojir's user avatar
  • 115
0 votes
1 answer
94 views

I'm given a task to read data from a text file and save it to a Set. Text file represents an imaginary bill containing certain item description and it's price, quantity and total sum. I only need item'...
kolsdj's user avatar
  • 3