{"id":166,"date":"2025-04-02T19:26:12","date_gmt":"2025-04-02T10:26:12","guid":{"rendered":"https:\/\/itexplore.org\/jp\/?p=166"},"modified":"2025-04-02T19:26:19","modified_gmt":"2025-04-02T10:26:19","slug":"substring-from-end-java","status":"publish","type":"post","link":"https:\/\/itexplore.org\/jp\/tips\/substring-from-end-java\/","title":{"rendered":"Java\u3067\u5f8c\u308d\u304b\u3089\u90e8\u5206\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3059\u308b"},"content":{"rendered":"<p>Java\u3067\u90e8\u5206\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f\u6587\u5b57\u5217\u578b\u306esubstring\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3044\u307e\u3059\u3002<code>str.substring(start, stop);<\/code> \u306e\u3088\u3046\u306b\u958b\u59cb\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3068\u7d42\u4e86\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u6307\u5b9a\u3057\u3066\u90e8\u5206\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3057\u307e\u3059\u304c\u3001\u958b\u59cb\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306b <strong><span data-color=\"#fffd6b\" style=\"background: linear-gradient(transparent 60%,rgba(255, 253, 107, 0.7) 0);\" class=\"vk_highlighter\">\u5bfe\u8c61\u6587\u5b57\u5217\u306e\u9577\u3055 - \u90e8\u5206\u6587\u5b57\u5217\u306e\u9577\u3055<\/span><\/strong> \u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u672b\u5c3e\u304b\u3089\u90e8\u5206\u6587\u5b57\u5217\u3092\u62bd\u51fa\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p><h2 class=\"wp-block-heading\">\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h2><div class=\"input-field-container source-code-container\"><pre class=\"wp-block-code\"><code>\n\/**\n * \u6587\u5b57\u5217\u306e\u672b\u5c3e\u304b\u3089\u90e8\u5206\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3059\u308b\u95a2\u6570\n *\n * @param str \u5143\u306e\u6587\u5b57\u5217\n * @param length \u53d6\u5f97\u3057\u305f\u3044\u90e8\u5206\u6587\u5b57\u5217\u306e\u9577\u3055\n * @return \u90e8\u5206\u6587\u5b57\u5217\n * @throws IllegalArgumentException str \u304c null \u307e\u305f\u306f length \u304c\u6587\u5b57\u5217\u306e\u9577\u3055\u3092\u8d85\u3048\u3066\u3044\u308b\u5834\u5408\u306b\u30b9\u30ed\u30fc\u3055\u308c\u307e\u3059\n *\/\npublic static String substringFromEnd(String str, int length) {\n\tif (str == null) {\n\t\tthrow new IllegalArgumentException(\"\u6587\u5b57\u5217\u304c null \u3067\u3059\u3002\");\n\t}\n\n\tif (str.length() < length) {\n\t\tthrow new IllegalArgumentException(\"\u6307\u5b9a\u3055\u308c\u305f\u9577\u3055\u304c\u6587\u5b57\u5217\u306e\u9577\u3055\u3092\u8d85\u3048\u3066\u3044\u307e\u3059\u3002\");\n\t}\n\n\treturn str.substring(str.length() - length);\n}\n<\/code><\/pre><a id=\"copy-source-code-Java-substringFromEnd\" class=\"action-button enable copy-source-code\" title=\"\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u30b3\u30d4\u30fc\u3057\u307e\u3059\u3002\"><i class=\"fa-regular fa-copy\"><\/i><\/a><\/div><p class=\"border-spacer\"><\/p><h3 class=\"wp-block-heading\">\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9<\/h3><div class=\"input-field-container source-code-container\"><pre class=\"wp-block-code\"><code>\nimport java.util.*;\n\npublic class Main {\n\tpublic static void main(String[] args) throws Exception {\n\t\tSystem.out.println(substringFromEnd(\"abcdefg\", 3)); \/\/ \u51fa\u529b: \"efg\"\n\t}\n\n\t\/**\n\t* \u6587\u5b57\u5217\u306e\u672b\u5c3e\u304b\u3089\u90e8\u5206\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3059\u308b\u95a2\u6570\n\t*\n\t* @param str \u5143\u306e\u6587\u5b57\u5217\n\t* @param length \u53d6\u5f97\u3057\u305f\u3044\u90e8\u5206\u6587\u5b57\u5217\u306e\u9577\u3055\n\t* @return \u90e8\u5206\u6587\u5b57\u5217\n\t* @throws IllegalArgumentException str \u304c null \u307e\u305f\u306f length \u304c\u6587\u5b57\u5217\u306e\u9577\u3055\u3092\u8d85\u3048\u3066\u3044\u308b\u5834\u5408\u306b\u30b9\u30ed\u30fc\u3055\u308c\u307e\u3059\n\t*\/\n\tpublic static String substringFromEnd(String str, int length) {\n\t\tif (str == null) {\n\t\t\tthrow new IllegalArgumentException(\"\u6587\u5b57\u5217\u304c null \u3067\u3059\u3002\");\n\t\t}\n\n\t\tif (str.length() < length) {\n\t\t\tthrow new IllegalArgumentException(\"\u6307\u5b9a\u3055\u308c\u305f\u9577\u3055\u304c\u6587\u5b57\u5217\u306e\u9577\u3055\u3092\u8d85\u3048\u3066\u3044\u307e\u3059\u3002\");\n\t\t}\n\n\t\treturn str.substring(str.length() - length);\n\t}\n}\n<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Java\u3067\u90e8\u5206\u6587\u5b57\u5217\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f\u6587\u5b57\u5217\u578b\u306esubstring\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002\u958b\u59cb\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306b\u5bfe\u8c61\u6587\u5b57\u5217\u306e\u9577\u3055 - \u90e8\u5206\u6587\u5b57\u5217\u306e\u9577\u3055\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u672b\u5c3e\u304b\u3089\u90e8\u5206\u6587\u5b57\u5217\u3092\u62bd\u51fa\u3067\u304d\u307e\u3059\u3002<\/p>\n","protected":false},"author":1,"featured_media":167,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"vkexunit_cta_each_option":"","footnotes":""},"categories":[4],"tags":[12],"class_list":["post-166","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tips","tag-java"],"_links":{"self":[{"href":"https:\/\/itexplore.org\/jp\/wp-json\/wp\/v2\/posts\/166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itexplore.org\/jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itexplore.org\/jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itexplore.org\/jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itexplore.org\/jp\/wp-json\/wp\/v2\/comments?post=166"}],"version-history":[{"count":2,"href":"https:\/\/itexplore.org\/jp\/wp-json\/wp\/v2\/posts\/166\/revisions"}],"predecessor-version":[{"id":169,"href":"https:\/\/itexplore.org\/jp\/wp-json\/wp\/v2\/posts\/166\/revisions\/169"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itexplore.org\/jp\/wp-json\/wp\/v2\/media\/167"}],"wp:attachment":[{"href":"https:\/\/itexplore.org\/jp\/wp-json\/wp\/v2\/media?parent=166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itexplore.org\/jp\/wp-json\/wp\/v2\/categories?post=166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itexplore.org\/jp\/wp-json\/wp\/v2\/tags?post=166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}