stringbuilder

Trim whitespace from the end of a StringBuilder without calling ToString().Trim() and back to a new SB

雨燕双飞 提交于 2019-12-04 15:35:13
问题 What is an efficient way to trim whitespace from the end of a StringBuilder without calling ToString().Trim() and back to a new SB new StringBuilder(sb.ToString().Trim()) . 回答1: The following is an extension method, so you can call it like this: sb.TrimEnd(); Also, it returns the SB instance, allowing you to chain other calls ( sb.TrimEnd().AppendLine() ). public static StringBuilder TrimEnd(this StringBuilder sb) { if (sb == null || sb.Length == 0) return sb; int i = sb.Length - 1; for (; i

【源码分析】面试问烂的equals和各种字符串、Integer比较

眉间皱痕 提交于 2019-12-04 15:33:38
今天在空闲时间聊天时发现,面试题中的equals问题,以及String、Integer等的判等问题还是讨论的比较激烈而且混乱。。。(滑稽) 其实网上有非常多关于这种面试题的文章或者博客,其实多去看看就可以。 不过。。。看了好多,都是通篇理论,感觉很干。思考之后,决定开一个新的模块,通过源码来解释面试题中、或者常见的一些问题中的原理以及本质,帮助有疑惑的小伙伴更容易、更深入的理解原理,以及相应的源码设计。 说到正题,这篇文章讨论的是关于equals在不同对象、以及特殊类型String、Integer上的实际原理。 1. ==与equals 这一部分属于J2SE最基础的东西了,算是常识性的,也没什么好说的。 基本数据类型,只有==,它是比较两个变量的值是否一致 引用数据类型的比对需要区别对待 ==:比较两个对象的内存地址是否相同 equals:调用一个对象的equals方法,与另一个对象比对 就因为这些最基本的知识,引发了很多面试题,咱们一一列举 2. String的常见面试题 public class Demo { public static void main(String[] args) throws Exception { String str1 = "123"; String str2 = "123"; String str3 = new String("123");

天天学JAVA-JAVA基础(2)

痞子三分冷 提交于 2019-12-04 14:42:59
如果觉得我写的还行,请关注我的博客并且点个赞哟。本文主要介绍JAVA基础相关问题,通过阅读本文,你将掌握以下10点 1.StringBuffer 、StringBuilder 和 String 的区别是什么? 2.在一个静态方法内调用一个非静态成员为什么是非法的? 3.接口和抽象类的区别是什么? 4.成员变量与局部变量的区别有哪些? 5一个类的构造方法的作用是什么? 若一个类没有声明构造方法,该程序能正确执行吗? 为什么? 6.静态方法和实例方法有何不同? 7.hashCode 介绍? 8.为什么Java中只有值传递? 9.线程有哪些基本状态? 10.一道阿里面试题,你会做吗? 1. StringBuffer 、StringBuilder 和 String 的区别是什么? 字符修改上的区别: String:不可变字符串; StringBuffer:可变字符串、效率低、线程安全; StringBuilder:可变字符序列、效率高、线程不安全; 初始化上的区别: String可以空赋值,StringBuffer不行,会报错(读者可自行测试) 小结: (1)如果要操作少量的数据用 String; (2)多线程操作字符串缓冲区下操作大量数据 StringBuffer; (3)单线程操作字符串缓冲区下操作大量数据 StringBuilder(推荐使用)。 2

刷题总结(持续更新中)

半世苍凉 提交于 2019-12-04 13:31:36
刷题总结 1,count数组 #include <iostream> #include <unordered_map> using namespace std; // 输入: 11223344455 // 输出:{1:2, 2: 2, 3: 2, 4: 3, 5: 1} void printNums(vector<int> nums) { for(int i = 0; i < nums.size(); i++) { cout << nums[i] << '\t'; } } vector<pair<int,int>> analysis(vector<int> nums) { unordered_map<int, int> mp; for(int i = 0; i < nums.size(); i++) { if(mp.find(nums[i]) == mp.end()) { mp.insert(pair(nums[i], 1)); } else { mp[nums[i]] = mp.find(nums[i])->second + 1; } } vector<pair<int, int>> result(mp.begin(), mp.end()); sort(result.begin(), result.end(), [](pair<int,int>&a, pair<int, int>

ThreadStatic特性

核能气质少年 提交于 2019-12-04 09:09:10
文章: ThreadStatic特性 地址:https://www.cnblogs.com/xuejietong/p/10997385.html 带有threadStaticAttribute标记的静态字段在线程之间不共享。每个执行线程都有一个单独的字段实例,并独立地设置和获取该字段的值。 如果在不同的线程上访问该字段,则它将包含不同的值。除了将threadStaticAttribute属性应用于字段之外,还必须将其定义为静态字段(在C中)或共享字段(在Visual Basic中)。不要为标记为threadStaticAttribute的字段指定初始值,因为此类初始化仅在类构造函数执行时发生一次(静态构造函数),因此只影响一个线程。 研究农业银行的支付接口demo时,发现代码中使用了这个特性: using System; using System.Collections; using System.Collections.Generic; using System.Text; namespace com.abc.trustpay.client { public class JSON { [ThreadStatic] private static string iJsonString = ""; public static void setJsonString(string

Where are strings more useful than a StringBuilder?

北城余情 提交于 2019-12-04 08:23:21
Lot of questions has been already asked about the differences between string and string builder and most of the people suggest that string builder is faster than string. I am curious to know if string builder is too good so why string is there? Moreover, can some body give me an example where string will be more usefull than string builder? It's not a case of which is more useful... A String is a String - one or more characters next to eachother. If you want to change a string in someway, it will simply create more strings because they are immutable . A StringBuilder is a class which creates

[LC] 168. Excel Sheet Column Title

萝らか妹 提交于 2019-12-04 05:35:09
Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB ... Example 1: Input: 1 Output: "A" Example 2: Input: 28 Output: "AB" Example 3: Input: 701 Output: "ZY" class Solution { public String convertToTitle(int n) { StringBuilder sb = new StringBuilder(); while (n > 0) { n -= 1; char letter = (char)(n % 26 + 'A'); sb.append(letter); n = n / 26; } return sb.reverse().toString(); } } 来源: https://www.cnblogs.com/xuanlu/p/11832920.html

基于xposed逆向微信、支付宝、云闪付来实现个人免签支付功能

空扰寡人 提交于 2019-12-04 04:51:48
  我的个人网站如何实现支付功能?   想必很多程序员都有过想开发一个自己的网站来获得一些额外的收入,但做这件事会遇到支付这个问题。目前个人网站通过常规手法是无法实现支付管理的,所有支付渠道都需要以公司的身份去申请。而且像支付宝、微信这些通道都是需要付费申请,且会收取部分手续费的。   今天我就给大家分享一下我的实现方案:《基于xposed逆向微信、支付宝、云闪付来实现个人免签支付框架》   可以先看下我做好的 支付测试页面(点我) ,目前已实现的个人免签支付功能有:      1、微信扫码支付,5秒内自动回调支付成功信息     2、支付宝二维码、支付宝红包、支付宝主动收款、支付宝银行卡转账,秒级回调     3、云闪付二维码,可使用云闪付App,招行建行等各大行App扫码支付,大概10秒左右自动回调       接下来给大家简单分享一下实现过程,这个过程其实是非常复杂的,关键点在于如何逆向微信支付宝云闪付这些App,找到核心函数钩子,然后写一个hook程序来模拟调用这些方法,来实现根据服务端传过来的金额,订单号自动调用微信支付宝生成支付二维码的函数得到相对应的支付二维码再传给服务端,然后监听微信支付宝的支付成功消息最终回调给服务端实现支付成功通知。这里面用到的核心技术点有:xposed逆向框架、apk反编译,网络抓包,apk动态调试等技术。  

ORA-01795: maximum number of expressions in a list is 1000

余生颓废 提交于 2019-12-04 04:16:46
问题 In c# we are building a query for NHibernate containing an "in statement". The number of expressions are crossing over 5000. If I execute the query I get an error. I need to find a good way to break the large string builder and store them in an array of string builder and execute multiple queries if needed to get the desired output. We have only one account that has over 5000 records and the rest are all below 100. Can someone suggest a way to resolve this? 回答1: The solution I have used is to

JavaSE常用API

混江龙づ霸主 提交于 2019-12-04 04:09:07
  1、Math.round(11.5)等于多少?Math.round(-11.5)又等于多少?     Math.round(11.5)的返回值是12,Math.round(-11.5)的返回值是-11.四舍五入的原理是在参数上加0.5然后进行取整。      2、switch是否能作用在byte上,是否能作用在long上,是否能作用在String上?     Java 5以前 switch(expr)中,expr只能是 byte、short、char、int 。从Java 5开始 ,Java引入了枚举类型, expr也可以是enum类型     从Java 7开始 , expr还可以是字符串String ,但是长整型(long)在目前所有的版本中都是不可以的      3、String、StringBuilder、StringBuffer的区别?     Java平台提供了两种类型的字符串:String和StringBuffer/StringBuilder,它们都可以储存和操作字符串,区别如下。       1)String(最终类)是只读字符串,也就意味这String引用的字符串内容是不可改变的。初学者可能会有这样的误解:           String str = "abc";           str = "bcd";         如上