I know this is a bit of a newbie question, but are there equivalents to C#'s string operations in Java?
Specifically, I'm talking about String.Format
and String.Join
.
C is a procedural, low level, and compiled language. Java is an object-oriented, high level, and interpreted language. Java uses objects, while C uses functions. Java is easier to learn and use because it's high level, while C can do more and perform faster because it's closer to machine code.
C is a Procedural Programming Language. Java is Object-Oriented language. C is more procedure-oriented. Java is more data-oriented. C is a middle-level language because binding of the gaps takes place between machine level language and high-level languages.
A common misconception is that if a language is similar to another, then it must be similar in functionality. While Java and C++ are similar in syntax, they are far more dissimilar in the way they execute and process.
The syntax of Java is largely influenced by C++ and C. Unlike C++, which combines the syntax for structured, generic, and object-oriented programming, Java was built almost exclusively as an object-oriented language.
The Java String object has a format
method (as of 1.5), but no join
method.
To get a bunch of useful String utility methods not already included you could use org.apache.commons.lang.StringUtils.
String.format. As for join, you need to write your own:
static String join(Collection<?> s, String delimiter) { StringBuilder builder = new StringBuilder(); Iterator<?> iter = s.iterator(); while (iter.hasNext()) { builder.append(iter.next()); if (!iter.hasNext()) { break; } builder.append(delimiter); } return builder.toString(); }
The above comes from http://snippets.dzone.com/posts/show/91
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With