- 博客(160)
- 资源 (5)
- 收藏
- 关注
原创 StringBuffer为什么是线程安全的,StringBuilder为什么不是是线程安全的,以及它们的使用场景(代码测试验证)
我们都知道StringBuffer是线程安全,而StringBuilder不是线程安全的(原因大家肯定也知道,StringBuffer中的方法都加了synchronized关键字)。所以网上很多资料都说,多线程不要用StringBuilder,否则会出现问题。但是它们的使用场景,我之前不是很明白,也和对多线程了解不深有一定原因。先看一段代码:package bingfa;/** * Stri...
2018-06-26 16:59:15 24152 7
原创 泛型Class<T>和 T
private T product;private Class product; 这两个有什么区别呢,查了资料才知道,单独的T 代表一个类型 而 Class代表这个类型所对应的类public T find(Class clazz, int id);根据类来反射生成一个实例,而单独用T没法做到。例T jsonStri
2016-07-03 20:38:03 431
原创 struts手动转发数据
HttpServletRequest request = ServletActionContext.getRequest();ServletActionContext.getActionContext(request).getSession().put("username",username+"哈哈");或ActionContext.getContext().put(
2016-07-01 21:09:39 338
原创 Servlet基本接口与类
1.HttpServletRequest接口 在软件包javax.servlet.http中,jsp内置对象request是该接口的一个实例。2.HttpServletResponse接口 在软件包javax.servlet.http中,jsp内置对象response是该接口的实例。3.HttpSession接口 在软件包javax.servlet.htt
2016-06-30 20:17:50 439
原创 JaveWeb--Servlet中实现转发
Servlet中实现转发在servlet中,一般是获取RequestDispatcher,然后调用forward方法进行转发。方法一用request获取。RequestDispatcher r = request.getRequestDispatcher("目标页面");方法二用ServletContext获取。1. 直接获取ServletCon
2016-06-27 22:05:02 520
原创 JAVA的MD5和SHA-256和SHA-512 的 Hash 算法的调用
class Encrypt{ /** * 传入文本内容,返回 SHA-256 串 * * @param strText * @return */ public String SHA256(final String strText) { return SHA(strText, "SHA-256"); } /** * 传入文本内容
2016-06-13 20:18:54 4589
原创 java抽象类-接口
接口可以继承(extends)接口,而且支持多重继承。但是抽象类不能继承接口,可以通过implements去实现接口,且可以不用实现接口的方法
2016-06-05 16:32:26 243
原创 leetcode-338-Counting Bits
338. Counting BitsGiven a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.
2016-03-19 11:09:40 1472
原创 利用JPcap进行抓包
JPCAP实际上并非一个真正去实现对数据链路层的控制,而是一个中间件,JPCAP调用wincap/libpcap,而给JAVA语言提供一个公共的接口,从而实现了平台无关性。在官方网站上声明,JPCAP支持FreeBSD 3.x, Linux RedHat 6.1, Fedora Core 4, Solaris, and Microsoft Windows 2000/XP等系统。参考
2016-03-14 22:05:04 8028 4
原创 leetcode-189.-Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solutions as
2016-03-09 20:58:19 279
原创 leetcode-328-Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in
2016-03-07 22:46:05 304
原创 计算机网络
1>.当一个IP数据报封装成链路层的帧时,此数据报的总长度(即报头区加上数据部分)一定不能超过下层的数据链路层的MTU值,否则无法传输。 因 此,我们需要对IP包进行分片,其中IP数据报的首部中,和IP数据包分片有关的字段为——总长度、标识、标志以及位偏移.分片由网络层的路由器完 成。 目的主机收到所有分片后,对分片进行重新组装还原的过程叫做IP
2016-03-06 14:50:51 310
原创 leetcode-257-Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]输出所有 从根
2016-03-03 11:29:29 297
原创 leetcode-88-Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m +
2016-03-02 18:11:32 284
原创 leetcode-26-Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with
2016-03-02 16:49:54 270
原创 leetcode-326-Power of Three
Given an integer, write a function to determine if it is a power of three.Follow up:Could you do it without using any loop / recursion?Credits:Special thanks to @dietpepsi for adding this
2016-01-11 23:22:00 571
原创 函数指针数组
函数指针数组#include //函数指针数组int func1(int n){ printf("func1: %d\n", n); return n;}int func2(int n){ printf("func2: %d\n", n); return n;}int main(){ //函数 //返回值
2015-12-30 22:06:47 411
原创 Django学习之manage.py使用
1.django-admin.py startproject mysite 开始一个项目,会初始化一些项目的结构文件2.python manage.py runserver ip:port 如: python manage.py runserver 127.0.0.1:8080 利用ip可以访问不在同一个主机的数据库3.python manage.py syncdb 注:会创建在se
2015-10-27 22:49:32 464
原创 Django学习笔记(一)
配置django运行环境,创建一个简单的项目。首先,安装Python。ubuntu下已经自带Python,故无需安装。Windows下安装也比较简单,不赘述。安装pip。pip是一个安装和管理Python包的工具,非常方便。sudo apt-get install python-pip安装django。有了pip,就容易安装任意Pyt
2015-10-19 13:26:23 442
原创 leetcode-292-Nim Game
Nim GameYou are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last
2015-10-18 20:20:42 408
原创 巴什博奕
下面这段来自白白の屋的文章的一段:巴什博弈:只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个。最后取光者得胜。 显然,如果n=m+1,那么由于一次最多只能取m个,所以,无论先取者拿走多少个,后取者都能够一次拿走剩余的物品,后者取胜。因此我们发现了如何取胜的法则:如果n=(m+1)r+s,(r为任意自然数,s≤m),那么先取者要拿走s个物品,如果
2015-10-18 20:14:11 406
原创 02-线性结构1 一元多项式的乘法与加法运算
02-线性结构1 一元多项式的乘法与加法运算 (20分)设计函数分别求两个一元多项式的乘积与和。输入格式:输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。输出格式:输出分2行,分别以指数递降方式输出乘积多项式以及和多项式非零项的系数和指数。数字间以空格分隔,
2015-10-04 22:25:45 569
原创 堆,优先队列
用最大堆实现排序#include // Myself 15-9-26#includeusing namespace std;void Adjust_Heap(int* a,int i,int n) { // 调整最大堆 if (i > n/2) return ; // 叶子节点 无需调整 int le = i<<1; int ri = i<<1|1; i
2015-09-26 19:54:26 305
原创 kinds of sort
各种排序算法#include#include#includeusing namespace std;void change(int *a,int *b) /// change{ int t=*a; *a=*b; *b=t;}void print(int *a,int n) /// print{ for(int i=0;i<n;i++)
2015-09-23 22:41:35 397
原创 leetcode-107-Binary Tree Level Order Traversal II
Binary Tree Level Order Traversal IIGiven a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For e
2015-09-23 18:36:06 378
原创 leetcode-102-Binary Tree Level Order Traversal
Binary Tree Level Order TraversalGiven a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,
2015-09-22 20:16:08 351
原创 leetcode-101-Symmetric Tree
Symmetric TreeFor example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the following is not: 1 / \ 2 2 \ \ 3 3Note:B
2015-09-21 21:13:19 317
原创 leetcode-283-Move Zeroes
Move ZeroesGiven an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 1
2015-09-21 13:20:51 335
原创 leetcode-110-Balanced Binary Tree
Balanced Binary TreeGiven a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subt
2015-09-21 12:57:37 347
原创 leetcode-172-Factorial Trailing Zeroes
Factorial Trailing ZeroesGiven an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.求 n!中,末尾的0连续有多少个。例如 10!=10*
2015-08-31 19:25:09 504
原创 leetcode-258-Add Digits
Add DigitsGiven a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2.
2015-08-31 13:19:39 584
原创 leetcode-263-Ugly Number
Ugly Number Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly
2015-08-24 09:47:40 596
原创 leetcode-118-Pascal's Triangle
Pascal's TriangleGiven numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1
2015-08-23 19:05:55 545
原创 leetcode-155-Min Stack
Min Stack Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of t
2015-08-04 18:14:58 570
原创 leetcode-67-Add Binary
Add BinaryGiven two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".两字符串表示的2进制数。求它们的和。直接模拟,从最后一位开始每一位都相加,结果保存在栈中。class Solut
2015-08-03 18:41:59 522
原创 leetcode-225-Implement Stack using Queues
Implement Stack using Queues Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() --
2015-08-03 17:44:43 548
原创 leetcode-232-Implement Queue using Stacks
Implement Queue using Stacks Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.pe
2015-08-03 17:29:45 372
原创 leetcode-190-Reverse Bits
Reverse Bits Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represen
2015-08-01 22:34:58 502
原创 leetcode-242-Valid Anagram
Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return f
2015-08-01 21:27:47 725
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人