4 ms·
I'm actually trying to learn java from a C# background. Two questions that immediately jumped out at me: - Do experienced java programming concatenate a bunch
by 727374 13y ago
I'm actually trying to learn java from a C# background. Two questions that immediately jumped out at me:
- Do experienced java programming concatenate a bunch of strings together, or is there a format method?
-Is anyone actually using Arraylist over Generics?
Also, is including 'switch' worth the screen real estate?
- irahul 13y ago> Do experienced java programming concatenate a bunch of strings together, or is there a format method? If you just want to append strings, use StringBuilder(not any different from C#). If you want to format strings, use String.format(analogous to C# string.Format) > Is anyone actually using Arraylist over Generics? Umm. ArrayList is itself generic. ArrayList<String> names = new ArrayList<String>();
- wtetzner 13y agoYou can use String.format: String.format("The value: %s", theValue); http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#format(java.lang.String http://docs.oracle.com/javase/6/docs/api/java/lang/String.ht..., java.lang.Object...)
- quacker 13y ago> Do experienced java programming concatenate a bunch of strings together, or is there a format method? Yeah, I've seen this a lot. IIRC, String concatenations with the + operator are compiled to use a StringBuffer for efficiency. There is also a static method String.format that works with C-like format strings. > Is anyone actually using Arraylist over Generics? I'm not sure exactly what you mean by this. The following is pretty standard Java, if you want a list of Strings. List<String> list = new ArrayList<String>(); The following gives you a list of Objects (the base type for all objects in Java): List list = new ArrayList(); If you put Strings into this list, then they come out as Objects. You'll have to cast to use them as Strings or the compiler complains.