stringbuilder

Scala StringBuilder

南笙酒味 提交于 2019-12-05 00:58:15
Is there an implicit method to convert scala.collection.mutable.StringBuilder to java.lang.StringBuilder? I am using a Java library (JCommander) in which one of the methods ( usage ) takes a java.jang.StringBuilder argument. You can't start with a Scala StringBuilder and then obtain the Java version. You can, however, wrap a java.lang.StringBuilder in the Scala version. So: val jsb = new java.lang.StringBuilder(); val sb = new StringBuilder(jsb); // Do Scala-y stuff with sb JCommander.whatever.usage(jsb); // Do more Scala-y stuff Since--not a guarantee, but true in practice right now (2.8, 2.9

Pass-by-value (StringBuilder vs String) [duplicate]

三世轮回 提交于 2019-12-05 00:37:32
This question already has an answer here: Is Java “pass-by-reference” or “pass-by-value”? 86 answers I do not understand why System.out.println(name) outputs Sam without being affected by the method's concat function, while System.out.println(names) outputs Sam4 as a result of the method's append method. Why is StringBuilder affected and not String? Normally, calling methods on a reference to an object affects the caller, so I do not understand why the String result remains unchanged. Thanks in advance public static String speak(String name) { name = name.concat("4"); return name; } public

How to maxmise the largest contiguous block of memory in the Large Object Heap

前提是你 提交于 2019-12-05 00:28:13
问题 The situation is that I am making a WCF call to a remote server which is returns an XML document as a string. Most of the time this return value is a few K, sometimes a few dozen K, very occasionally a few hundred K, but very rarely it could be several megabytes (first problem is that there is no way for me to know). It's these rare occasions that are causing grief. I get a stack trace that starts: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. at

浅谈String、StringBuffer和StringBuilder类的区别

强颜欢笑 提交于 2019-12-04 23:16:13
1、均可对字符串进行修改,但StringBuffer和StringBuilder类的对象进行多次修改时,不产生新的未使用对象。   String 的底层是用final修饰的char数组,变量的内容不可变——内存占用高,资源利用率低;   StringBuffer和StringBuilder类 则继承了AbstractStringBuilder类,其未使用final修饰char数组,变量内容动态更新——无效数组等待垃圾回收,减少资源占用; 2、StringBuilder相较于StringBuffer有速度优势。 3、StringBuilder和StringBuffer最大的区别是StringBuilder不是线程安全(不能同步访问)。   StringBuffer在拼接字符串时通过使用同步锁,实现线程安全;   StringBuilder未使用同步锁机制,故效率高于Stringbuffer; 来源: https://www.cnblogs.com/yangjuanjuan/p/11887547.html

When should you explicitly use a StringBuilder? [duplicate]

安稳与你 提交于 2019-12-04 22:28:24
This question already has an answer here: StringBuilder vs String concatenation in toString() in Java 18 answers String concatenation in Java - when to use +, StringBuilder and concat [duplicate] 9 answers As I understand it, when I do String baz = "foo" + "bar" + "123" the Java compiler internally replaces the expression with a StringBuilder . However our Java teacher told us that it is good practice to always use a StringBuilder explicitly... Am I correct in assuming I will only need to explicitly use StringBuilder when concatenating inside loops as indicated in an answer to Stack Overflow

Converting a StringBuilder To Integer Values In Java [duplicate]

荒凉一梦 提交于 2019-12-04 22:10:21
This question already has an answer here: How to split a string in Java 34 answers Well the question is very simple. Lets say there is a StringBuilder sb Inside of sb numbers like this: "25 9631 12 1895413 1 234564" How to get those numbers one by one and initialize them into an ArrayList<Integer> list or to be more specific is it possible? Thanks for checking! Try to split that string like: String[] numbers = sb.toString().split(" ");//if spaces are uneven, use \\s+ instead of " " for (String number : numbers) { list.add(Integer.valueOf(number)); } Well my solution may not be the best here ,

java基础阶段几个必会面试题

别说谁变了你拦得住时间么 提交于 2019-12-04 21:12:15
摘自: https://www.cnblogs.com/zn19961006/p/11869182.html java基础阶段几个必会面试题 目录 1.说出你对面向对象的理解 在我理解,面向对象是向现实世界模型的自然延伸,这是一种“万物皆对象”的编程思想。在现实生活中的任何物体都可以归为一类事物,而每一个个体都是一类事物的实例。面向对象的编程是以对象为中心,以消息为驱动,所以程序=对象+消息。 面向对象有三大特性,封装、继承和多态。 封装就是将一类事物的属性和行为抽象成一个类,使其属性私有化,行为公开化,提高了数据的隐秘性的同时,使代码模块化。这样做使得代码的复用性更高。 继承则是进一步将一类事物共有的属性和行为抽象成一个父类,而每一个子类是一个特殊的父类--有父类的行为和属性,也有自己特有的行为和属性。这样做扩展了已存在的代码块,进一步提高了代码的复用性。 如果说封装和继承是为了使代码重用,那么多态则是为了实现接口重用。多态的一大作用就是为了解耦--为了解除父子类继承的耦合度。如果说继承中父子类的关系式IS-A的关系,那么接口和实现类之之间的关系式HAS-A。简单来说,多态就是允许父类引用(或接口)指向子类(或实现类)对象。很多的设计模式都是基于面向对象的多态性设计的。 2.JVM的内存区及其GC算法 参考: https://blog.csdn.net/anjoyandroid

Java StringBuffer&StringBuilder

醉酒当歌 提交于 2019-12-04 17:35:41
Java StringBuffer和StringBuilder类 当字符串需要修改的时候使用StringBuffer和StringBuilder类 StringBuffer和StringBuilder类的区别 ​ StringBuffer:速度快,不是线程安全的 ​ StringBuilder:速度慢,线程安全 StringBuffer方法: 1、append():追加字符串 2、reverse():逆序 3、delete(start,end):删除字符串 4、insert(index,string):插入字符串 5、replace(start,end,str):替换字符串 6、capacity():返回当前容量 7、getChars():截取字符串 余下的与String方法一样 来源: https://www.cnblogs.com/Mr-l/p/11875623.html

How can I change this StringBuilder-to-XML code to LINQ-to-XML?

五迷三道 提交于 2019-12-04 16:06:38
In my application I build an XML file with this code using StringBuilder : StringBuilder sb = new StringBuilder(); sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine); sb.Append(String.Format("<{0}>{1}", _pluralCamelNotation, Environment.NewLine)); for (int index = 0; index < 3; index++) { sb.Append(String.Format("\t<{0}>{1}", _singularCamelNotation, Environment.NewLine)); foreach (DataType dataType in _allDataTypes) { sb.Append(String.Format("\t\t<{0}>{2}</{0}>{1}", dataType.CamelCaseNotation, Environment.NewLine, dataType.GetDummyData())); } sb.Append(String.Format(

String or StringBuilder return values?

Deadly 提交于 2019-12-04 16:01:28
问题 If I am building a string using a StringBuilder object in a method, would it make sense to: Return the StringBuilder object, and let the calling code call ToString()? return sb; OR Return the string by calling ToString() myself. return sb.ToString(); I guess it make a difference if we're returning small, or large strings. What would be appropriate in each case? Thanks in advance. Edit: I don't plan on further modifying the string in the calling code, but good point Colin Burnett. Mainly, is