stringbuilder

How to get last two digit from a year which a user inputs

别等时光非礼了梦想. 提交于 2019-12-13 05:08:39
问题 I Have been playing with this for while, and I can not seem to get my mind around how I can get this task accomplished. My task : I need get the last two digits of a year that a user has entered. Example : A user enters the July 2 , 2014; I need to get the last two digits of year 2014 which is "14" and divide it by 4. This will give me 3.5; however I will disregard the ".5" and just keep the 3. Research : I have been reading my Textbook, and seen one approach that I may be able to use which

Passing xml string as document returning null

心不动则不痛 提交于 2019-12-13 02:37:59
问题 I have seen many similar questions on stackoverflow and tried a lot but still no success. So posting my problem. Here is my program: Get the http output of a response which is in xml. Store the response in a string. Parse the string using xml dom parser. Fetch the element. <RESULTS> <DEVICE name="qwewewew"> <PORT name="ilo"> <DB_SOURCE>abncd</DB_SOURCE> <WIRE_TYPE>ilo</WIRE_TYPE> <CONNECTS>abncd</CONNECTS> </PORT> <PORT name="onboard-1"> <DB_SOURCE>abncd</DB_SOURCE> <WIRE_TYPE>net</WIRE_TYPE>

StringBuilder: ArrayIndexOutOfBoundsException

旧城冷巷雨未停 提交于 2019-12-12 21:29:05
问题 We're experiencing a strange issue with WebSphere 7/ IBM JDK 6, where one of the nodes has some initialization issue. We have some code which calls InitialContext.lookup and on this node we're getting sometimes the following exception: Caused by: java.lang.ArrayIndexOutOfBoundsException at java.lang.String.getChars(String.java:666) at java.lang.StringBuilder.append(StringBuilder.java:207) at javax.naming.spi.NamingManager.getURLContext(NamingManager.java:646) at javax.naming.InitialContext

differences between StringBuilder in Java and C#

元气小坏坏 提交于 2019-12-12 12:06:02
问题 I am converting Java code to C#. The StringBuilder class in Java seems to have many more methods than the C# one. I am interested in (say) the Java functionality sb.indexOf(s); sb.charAt(i); sb.deleteCharAt(i); which seems to be missing in C#. I suppose the first two could be modelled by sb.ToString().IndexOf(s); sb.ToString().CharAt(i); but would the third operate on a copy of the contents of the sb rather than the actual contents? Is there a common way of adding this functionality to all

Why isn't string concatenation automatically converted to StringBuilder in C#? [duplicate]

穿精又带淫゛_ 提交于 2019-12-12 09:36:14
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Why is String.Concat not optimized to StringBuilder.Append? One day I was ranting about a particular Telerik control to a friend of mine. I told him that it took several seconds to generate a controls tree, and after profiling I found out that it is using a string concatenation in a loop instead of a StringBuilder. After rewriting it worked almost instantaneously. So my friend heard that and seemed to be

java中String、StringBuffer和StringBuilder的区别(简单介绍)

老子叫甜甜 提交于 2019-12-12 08:00:15
java中String、StringBuffer和StringBuilder的区别(简单介绍) 简单介绍 java中用于处理字符串常用的有三个类: 1、java.lang.String 2、java.lang.StringBuffer 3、java.lang.StrungBuilder 三者共同之处:都是final类,不允许被继承,主要是从性能和安全性上考虑的,因为这几个类都是经常被使用着,且考虑到防止其中的参数被参数修改影响到其他的应用。 StringBuffer是线程安全,可以不需要额外的同步用于多线程中; StringBuilder是非同步,运行于多线程中就需要使用着单独同步处理,但是速度就比StringBuffer快多了; StringBuffer与StringBuilder两者共同之处:可以通过append、indert进行字符串的操作。 String实现了三个接口:Serializable、Comparable<String>、CarSequence StringBuilder只实现了两个接口Serializable、CharSequence,相比之下String的实例可以通过compareTo方法进行比较,其他两个不可以。 这三个类之间的区别主要是在两个方面,即运行速度和线程安全这两方面。   1、首先说运行速度,或者说是执行速度, 在这方面运行速度快慢为

Resizeable Number Pyramid Panel with Swing

最后都变了- 提交于 2019-12-12 06:28:20
问题 I am trying to create a resizable window with Swing and AWT components which displays numbers in a pyramid fashion depending on what the frame is sized to but I have no idea really where to start. I am not sure if I am supposed to use JLabel or StringBuilder. If it can be done without using action listeners, that would be preferred. I need some assistance. 回答1: I would simply create a dedicated panel and override the method paintComponent. Then using the FontMetrics and the size of that panel

Java Socket编程

隐身守侯 提交于 2019-12-12 05:01:03
Java Socket编程 对于Java Socket编程而言,有两个概念,一个是ServerSocket,一个是Socket。服务端和客户端之间通过Socket建立连接,之后它们就可以进行通信了。首先ServerSocket将在服务端监听某个端口,当发现客户端有Socket来试图连接它时,它会accept该Socket的连接请求,同时在服务端建立一个对应的Socket与之进行通信。这样就有两个Socket了,客户端和服务端各一个。 对于Socket之间的通信其实很简单,服务端往Socket的输出流里面写东西,客户端就可以通过Socket的输入流读取对应的内容。Socket与Socket之间是双向连通的,所以客户端也可以往对应的Socket输出流里面写东西,然后服务端对应的Socket的输入流就可以读出对应的内容。下面来看一些服务端与客户端通信的例子: 1、客户端写服务端读 服务端代码 1 public class Server { public static void main(String args[]) throws IOException { //为了简单起见,所有的异常信息都往外抛 int port = 8899; //定义一个ServerSocket监听在端口8899上 ServerSocket server = new ServerSocket(port); /

1211-2019-LEETCODE-countAndSay(数数然后读出来)

风格不统一 提交于 2019-12-12 04:59:13
给定1然后2是读出1的内容,以此类推。 1 = 1; 2 = 11; 3 = 21; 4 = 1211; 5 = 111221; 题目有点难理解,代码还是比较好写的。效率待优化,因为要不断地拼接数据,所以用StringBuilder比较好一点。 public String countAndSay ( int n ) { String [ ] strings = new String [ n ] ; strings [ 0 ] = "1" ; for ( int i = 1 ; i < n ; i ++ ) { StringBuilder builder = new StringBuilder ( "" ) ; for ( int j = 0 ; j < strings [ i - 1 ] . length ( ) ; j ++ ) { char a = strings [ i - 1 ] . charAt ( j ) ; int num = 1 ; while ( j < strings [ i - 1 ] . length ( ) - 1 && strings [ i - 1 ] . charAt ( j + 1 ) == a ) { num ++ ; j ++ ; } builder . append ( String . valueOf ( num ) + strings [

Alternative to switch — replacing characters

醉酒当歌 提交于 2019-12-12 04:55:07
问题 I was required to write a program for class which: Accepted a .txt file Convert numbers 0-9 in the file to their text equivalent (if the number is at beginning of sentence, use uppercase) Print the finished sentences to a new file Example: The 8 eggs were separated into 3 groups. Would be converted to: The eight eggs were separated into three groups. Currently I am using a (very) long switch statement with a StringBuilder to complete the task: switch(sb.charAt(i)){ case '0': if (i == 0) sb