concat « string « Java Data Type Q&A

1. Is there a difference between String concat and the + operator in Java?


java String concatenation
I'm curious what is the difference between the two. The way I understand the string pool is this: This creates 3 string objects in the string pool, for ...

2. Java - is there an Inbuilt function for concatenating the Strings in a String[]?

Or a better way than this?

String concat(String[] strings) {
  StringBuilder out = new StringBuilder();

  for(String next: strings) {

  return out.toString();
No worries if ...

3. Concat over '+' operator for string concatenation

String today = someSimpleDateFormat.format(new Date());
Calendar rightNow = Calendar.getInstance();
int hour = rightNow.get(Calendar.HOUR_OF_DAY);
int minute = rightNow.get(Calendar.MINUTE);
String hourString = String.valueOf(hour);
String minuteString = String.valueOf(minute);

if(hourString.length() == 1){
    hourString = '0'.concat(hourString);

if(minuteString.length() == 1){

4. why concat() is not working here? , java

Consider the code below,

String s = "TEST";
String s2 = s.trim();

System.out.println("S = "+s);
System.out.println("S2 = "+s2);
Output obtained :
BUILD SUCCESSFUL (total time: 0 seconds)
Why "ING" is not concatenated?

5. Java; is += more efficient that .concat?

I've been reading code produced by other developers on my team, they seem to favour using += for String concatenation, whereas I prefer using .concat() as it feels easier to read. I'm ...

6. Difference between string.concat() and + operator

Possible Duplicate:
Is there a difference between String concat and the + operator in Java?
Is there any difference between:
String A = "Hello";
String B = A.concat("Testing");
String ...

7. String class: + vs concat

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - ...

8. String Concat

Originally posted by jignesh soni: So how do you know when next GC is and my other part is unanswered yet. I am not clear wheen we concat two strings, third string will be created and which one of these three strings will not have reference, probably newly created concatted string right ? if you write the code as in your ...

9. Difference between '+' and concat() method in String

Not quite. + does use a StringBuffer or StringBuilder, but concat() creates a new char[] with the contents of the current String and the String to append, and returns a new String based on that array: public String concat(String str) { int otherLen = str.length(); if (otherLen == 0) { return this; } char buf[] = new char[count + otherLen]; getChars(0, ...

10. String concat

13. String Concat

Hi, I would like to concat few strings into one. Below shows the code (as suggested yesterday in the previous post) of extracting certain values from string a. for (int r = 1;r"+newStr3); } ...

14. adding string methods? not concat

How can I add together strings such as "1" + "2" = "3" not "1" + "2" = "12" if there is no way to do this, how can I convert a string value such as "1" to 1, so I can then add these integers together? Any help is appreciated. thanks, Patrick.

15. Method w/ String's concat not working

16. String Manipulation.concat

17. Using String.concat() inside a function

rocketGhost wrote: Hello everyone, Hopefully this will be easy to figure out - I am primarily a C++ programmer, learning Java. Thus far I have been under the impression that when I pass any Object to a function, it's always like passing a pointer in C++ (unless I use 'final'); It's just like passing a pointer in C (which is always ...

18. String concat Problem

20. Concat to a single string

Hi I need help to concat string from a file. I want to concat just the 2's into a single string but i want to keep the order and use only one vector as the result. Below is the sample data 1|000000000010000000|CLUTCH,OILWELL E-2000,NEUTRAL BRAKE|KBSB|19971008|20040322||VIT|01AAAA|0111010023|PCE||||||| 0.0||05| 2|000000000010000000|CLUTCH,OILWELL E-2000,NEUTRAL BRAKE. 2|000000000010000000|PARTS FOR DRAWWORKS AND HOISTS. 2|000000000010000000|RATING : 2,000 HP. 2|000000000010000000|DRILLING DEPTH : 20,000 ...

21. string.concat(str) and string += str

22. String concat

23. how to concat "tab" to string ??

24. Concat two string without 'losing' memory...

26. string concat problem

public String concat(String str)Concatenates the specified string to the end of this string. If the length of the argument string is 0, then this String object is returned. Otherwise, a new String object is created, representing a character sequence that is the concatenation of the character sequence represented by this String object and the character sequence represented by the argument string. ...

27. String Concat doesn't work