{"id":1135,"date":"2022-05-23T11:05:14","date_gmt":"2022-05-23T03:05:14","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=1135"},"modified":"2022-05-23T11:05:14","modified_gmt":"2022-05-23T03:05:14","slug":"%e7%ae%97%e6%b3%95%e9%a2%98java%e5%b8%b8%e7%94%a8%e5%ba%93%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2022\/05\/23\/%e7%ae%97%e6%b3%95%e9%a2%98java%e5%b8%b8%e7%94%a8%e5%ba%93%e5%87%bd%e6%95%b0\/","title":{"rendered":"\u7b97\u6cd5\u9898JAVA\u5e38\u7528\u5e93\u51fd\u6570"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u5b57\u7b26\u4e32\u64cd\u4f5c<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>1\u3001\u6574\u6570\u8f6c\u5b57\u7b26\u4e32\uff1a\nString str = String.valueOf(a);\n\n2\u3001\u5b57\u7b26\u4e32\u8f6c\u5b57\u7b26\u6570\u7ec4\uff1a\nchar&#91;] chars = str.toCharArray();\n\n3\u3001\u5b57\u7b26\u4e32\u66ff\u6362\uff1a\nstr.replace('a','b');\n\n4\u3001\u5b57\u7b26\u4e32\u53bb\u9664\u7a7a\u683c\nstr.trim();\n\n5\u3001\u5b57\u7b26\u4e32\u62fc\u63a5\uff1a\nStringBuilder sb = new StringBuilder();\nsb.append(a);\nsb.length(a);\nsb.deleteCharAt(index);\n\n6\u3001\u622a\u53d6\u5b57\u7b26\u4e32\uff1a\nstr.substring(start,end);\/\/\u542b\u524d\u4e0d\u542b\u540e\uff0c\u4e5f\u53ef\u4ee5\u53ea\u6709\nstr.substring(start);\n\n7\u3001\u5b57\u7b26\u4e32\u83b7\u53d6\u67d0\u4e2a\u5b57\u7b26\u7684\u4f4d\u7f6e\uff1a\nstr.indexOf('a');\n\n8\u3001\u5b57\u7b26\u4e32\u5206\u5272\uff1a\nstr.split(\"\\\\s+\"); \u6309\u7a7a\u683c\u5206\u5272\nlist\/deque\u91cd\u7ec4\u6210String:\nString.join(\"\",list);String.join(\"\",deque);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u6570\u7ec4<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>1\u3001\u6570\u7ec4\u521d\u59cb\u5316\uff1a\nchar&#91;] array = new char&#91;len];\nint&#91;] arr = {1,2,3};\nint&#91;] arr = new int&#91;]{1,2,3,4,5};\n\n2\u3001\u6570\u7ec4\u81ea\u5b9a\u4e49\u6392\u5e8f\uff1a\nArrays.sort(nums)\n\n3\u3001\u6570\u7ec4\u8f6clist\uff1a\nArrayList&lt;String> arraylist = new ArrayList&lt;Strin>(Array.asList(arrays));\nList&lt;String> list = Arrays.asList(arrays);\nList&lt;String> list2 = new ArrayList&lt;String>(arrays.length);\nCollection.addAll(list2,arrays);\n\n4\u3001Array\u6839\u636e\u5143\u7d20\u67e5\u627e\u4f4d\u7f6e\uff1a\nint position = Arrays.binarySearch(arrays,\"f\");\n\n5\u3001array\u4e2d\u586b\u5145\u5143\u7d20\uff1a\nArrays.fill(array,Integer.MAX_VALUE);\n\n\n6\u3001\u57fa\u672c\u7c7b\u578b\u6570\u7ec4\u8f6c\u6210\u5305\u88c5\u7c7b\u578bLIst;\nint&#91;] nums = {1,2,3};\nArrays.stream(nums).boxed().collect(Collectors.toList());\n\n7\u3001list\u8f6c\u6570\u7ec4\uff08\u53ea\u9002\u7528\u4e8elist\u6210\u5458\u662f\u5305\u88c5\u7c7b\u578b\uff09\nString&#91;] strs = list.toArray(new String&#91;list.size]);\n\n8\u3001list\u590d\u5236\uff1a\ntargetList.addAll(sourceList);\n\n9\u3001list\u81ea\u5b9a\u4e49\u6392\u5e8f\uff1a\nCollections.sortt()\n\n10\u3001list\u53cd\u8f6c\uff1a\nCollections.reverse(list);\n\n11\u3001list\u6309\u4f4d\u7f6e\u79fb\u9664\u5143\u7d20\uff1a\nlist.remove(index);\n\n12\u3001list\u83b7\u53d6\u67d0\u4e2a\u5143\u7d20\u7684\u4f4d\u7f6e\uff1a\nlist.indexOf(value) \/\/\u9ed8\u8ba4\u8fd4\u56de\u7b2c\u4e00\u4e2a\u5143\u7d20\u6240\u5728\u4f4d\u7f6e\n\n13\u3001list\u6dfb\u52a0\u5143\u7d20\uff1a\nlist.add(value) \/\/\u5728\u961f\u5c3e\u6dfb\u52a0list.add(place,value);\/\/\u5728\u6307\u5b9a\u4f4d\u7f6e\u6dfb\u52a0<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u6808\u548c\u961f\u5217<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\u6808\n\n\u6808\u521d\u59cb\u5316\uff1a\nStack stack = new Stack();\n\n\u6808\u63d2\u5165\u5143\u7d20\nstack.push();\n\n\u6808\u5f39\u51fa\u5143\u7d20\uff1a\nstack.pop();\n\n\u6808\u53d6\u6808\u9876\u5143\u7d20\uff0c\u4e0d\u5220\u51cf\u5143\u7d20\uff1a\nstack.peek();\n\n\u5224\u65ad\u6808\u662f\u4e0d\u662f\u7a7a\uff1a\nstack.isEmpty();\n\n\u961f\u5217\nQueue&lt;String> queue = new LinkedList&lt;String>();\n\u961f\u5217\u63d2\u5165\u5143\u7d20\uff1a\nqueue.offer(elment);\n\n\u961f\u5217\u5f39\u51fa\u5143\u7d20\nqueue.peek();\n\n\u961f\u5217\u5934\u5143\u7d20\uff1a\nqueue.peek();\n\n\u53cc\u7aef\u961f\u5217\uff1a\n\u53cc\u7aef\u961f\u5217\u521d\u59cb\u5316\uff1a\nDeque&lt;String> d = new ArrayDeque&lt;String>();\n\n\u53cc\u7aef\u961f\u5217\u961f\u9996\u63d2\u5165\u5143\u7d20\uff1a\nd.offerFirst(ele);\n\n\u53cc\u7aef\u961f\u5217\u961f\u5c3e\u63d2\u5165\u5143\u7d20\uff1a\nd.offer();\nd.offerLast();\n\n\n\u53cc\u7aef\u961f\u5217\u961f\u9996\u5f39\u51fa\u5143\u7d20\uff1a\ndeque.pollFirst();\ndeque.poll();\n\n\u53cc\u7aef\u961f\u5217\u961f\u5c3e\u5f39\u51fa\u5143\u7d20\ndeque.pollLast();<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001\u54c8\u5e0c\u8868Map<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>groupItemsMap.computeIfAbent(group&#91;items],key->new ArrayList&lt;Integer>().add(item))\n\n\u6dfb\u52a0\u5143\u7d20\uff1a\nHashMap&lt;K,V> map = new HashMap&lt;K,V>();\nmap.put(K key,V value);\/\/\u4f1a\u8986\u76d6\u539f\u672c\u542bkey\u7684\u5143\u7d20\n\n\u5224\u65ad\uff1a\nmap.containsKey(K key);\nmap.containValue(V value);\n\n\nmap\u904d\u5386\uff1a\nEntrySet\u904d\u5386(\u6027\u80fd\u6700\u597d\uff09\uff1a\nMap&lt;K,V> map = new HashMap&lt;K,V>();\nfor(Map.Entry&lt;K,V> entry : map.entrySet()){\n    entry.getKey();\n    entry.getValue();\n}\n\n\nKeySet\u6216\u8005\u662fValues\u904d\u5386\uff1a\nfor(K key : map.keySet()){   \n}\n\nfor(V value : values : map.values()){    \n}\n\n\u4f7f\u7528Iterator\u904d\u5386\uff1a\nIterator&lt;Map.Entry&lt;K,V> it = map.entrySet().iterator();\nwhile(it.hasNext()){\n    Map.Entry&lt;K,V> entry = it.next();\n    entry.getKey();\n    entry.getValue();\n}\n\nLambda\nmap.forEach(key,value) -> {   \n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001\u51fd\u6570<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Math.max(a,b);\nMath.min(a,b);\nMath.pow(a,digit);\nMath.ceil(a)\/\/a\u4e3adouble\uff0c\u5e76\u4e14\u51fd\u6570\u8fd4\u56de\u503c\u4e5f\u4e3adouble\uff0c\u5411\u4e0b\u53d6\u6574\nMath.floor(a)\/\/\u5411\u4e0a\u53d6\u6574\n\njava.util.Random()\u65b9\u6cd5\u6458\u8981\uff1a\nprotected int next(int bits)\uff1a\u751f\u6210\u4e0b\u4e00\u4e2a\u4f2a\u968f\u673a\u6570\u3002\nboolean nextBoolean()\uff1a\u8fd4\u56de\u4e0b\u4e00\u4e2a\u4f2a\u968f\u673a\u6570\uff0c\u5b83\u662f\u53d6\u81ea\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u5e8f\u5217\u7684\u5747\u5300\u5206\u5e03\u7684boolean\u503c\u3002\nvoid nextBytes(byte&#91;] bytes)\uff1a\u751f\u6210\u968f\u673a\u5b57\u8282\u5e76\u5c06\u5176\u7f6e\u4e8e\u7528\u6237\u63d0\u4f9b\u7684 byte \u6570\u7ec4\u4e2d\u3002\n\ndouble nextDouble()\uff1a\u8fd4\u56de\u4e0b\u4e00\u4e2a\u4f2a\u968f\u673a\u6570\uff0c\u5b83\u662f\u53d6\u81ea\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u5e8f\u5217\u7684\u3001\u57280.0\u548c1.0\u4e4b\u95f4\u5747\u5300\u5206\u5e03\u7684 double\u503c\u3002\n\nfloat nextFloat()\uff1a\u8fd4\u56de\u4e0b\u4e00\u4e2a\u4f2a\u968f\u673a\u6570\uff0c\u5b83\u662f\u53d6\u81ea\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u5e8f\u5217\u7684\u3001\u57280.0\u548c1.0\u4e4b\u95f4\u5747\u5300\u5206\u5e03float\u503c\u3002\n\ndouble nextGaussian()\uff1a\u8fd4\u56de\u4e0b\u4e00\u4e2a\u4f2a\u968f\u673a\u6570\uff0c\u5b83\u662f\u53d6\u81ea\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u5e8f\u5217\u7684\u3001\u5448\u9ad8\u65af\uff08\u201c\u6b63\u6001\u201d\uff09\u5206\u5e03\u7684double\u503c\uff0c\u5176\u5e73\u5747\u503c\u662f0.0\u6807\u51c6\u5dee\u662f1.0\u3002\n\nint nextInt()\uff1a\u8fd4\u56de\u4e0b\u4e00\u4e2a\u4f2a\u968f\u673a\u6570\uff0c\u5b83\u662f\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u7684\u5e8f\u5217\u4e2d\u5747\u5300\u5206\u5e03\u7684 int \u503c\u3002\n\nint nextInt(int n)\uff1a\u8fd4\u56de\u4e00\u4e2a\u4f2a\u968f\u673a\u6570\uff0c\u5b83\u662f\u53d6\u81ea\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u5e8f\u5217\u7684\u3001\u5728\uff08\u5305\u62ec\u548c\u6307\u5b9a\u503c\uff08\u4e0d\u5305\u62ec\uff09\u4e4b\u95f4\u5747\u5300\u5206\u5e03\u7684int\u503c\u3002\n\nlong nextLong()\uff1a\u8fd4\u56de\u4e0b\u4e00\u4e2a\u4f2a\u968f\u673a\u6570\uff0c\u5b83\u662f\u53d6\u81ea\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u5e8f\u5217\u7684\u5747\u5300\u5206\u5e03\u7684 long \u503c\u3002\nvoid setSeed(long seed)\uff1a\u4f7f\u7528\u5355\u4e2a long \u79cd\u5b50\u8bbe\u7f6e\u6b64\u968f\u673a\u6570\u751f\u6210\u5668\u7684\u79cd\u5b50;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001\u8f93\u5165\u8f93\u51fa<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>1\u3001\u8f93\u5165\n\nScanner input = new Scanner(System.in);\ninput.next();\/\/\u8fd4\u56de\u503c\u4e3aString\ninput.nextInt()\/\/\u8fd4\u56de\u503c\u4e3aint\ninput.hasNext();\/\/\u8fd4\u56de\u503c\u4e3aboolean\n\n2\u3001\u8f93\u5165\u4e00\u884c\u6570\u5b57\uff0c\u6570\u5b57\u95f4\u4ee5\u9017\u53f7\u5206\u5272\uff0c\u5c06\u6570\u7ec4\u5b58\u5165\u6570\u7ec4\nScanner input = new Scanner(System.in);\nString s = input.nextLine();\nString&#91;] num = s.split(\",\");\nint size = num.length();\nint&#91;] a = new int&#91;size];\nfor(int i = 0; i &lt; size; i++){\n    a&#91;i] = Integer.parseInt(num&#91;i]);\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u5b57\u7b26\u4e32\u64cd\u4f5c \u4e8c\u3001\u6570\u7ec4 \u4e09\u3001\u6808&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1136,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4],"tags":[],"class_list":["post-1135","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=1135"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1135\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media\/1136"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=1135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=1135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=1135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}