{"id":121,"date":"2007-08-17T21:59:00","date_gmt":"2007-08-17T21:59:00","guid":{"rendered":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/"},"modified":"2007-08-17T21:59:00","modified_gmt":"2007-08-17T21:59:00","slug":"how-to-return-multiple-parameter-values-in-java","status":"publish","type":"post","link":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/","title":{"rendered":"How to return multiple parameter values in Java"},"content":{"rendered":"<p>Here&#8217;s a java tip I discovered. <br \/>Java doesn&#8217;t allow functions to return multiple parameters. You can&#8217;t pass by reference like in C\/C++. <br \/>Say you have this function in C or C++:<\/p>\n<p>int get(int a, int* b, int* c)<br \/>{<br \/> *b = 2 * a;<br \/> *c = 3 * a;<\/p>\n<p> return 4 * a;<br \/>}<\/p>\n<p>Now you want to write that function in Java. One option is to create an object which stores 3 integer values and return that. <br \/>An option involving less work, is the following:<br \/>Java lets you pass in an object, to which you can modify the content of the object, so:<br \/>First create a java class which stores an integer:<\/p>\n<p>public class _Integer<br \/>{<br \/> public int _integer;<\/p>\n<p> public _Integer<br \/> {<br \/> }<br \/>}<\/p>\n<p>Now pass this object to your java function whenever you need to return more than one value:<\/p>\n<p>int a = 1;<br \/>_Integer bInteger = new _Integer();<br \/>_Integer cInteger = new _Integer();<\/p>\n<p>int d = get(a, bInteger, cInteger);<\/p>\n<p>int get(int a, _Integer b, _Integer c)<br \/>{<br \/> b._integer = 2 * a;<br \/> c._integer = 3 * a;<\/p>\n<p> return 4 * a;<br \/>}<\/p>\n<p>If you need to pass doubles, create a _Double class, etc.<\/p>\n<p>I thought that was a pretty cool workaround I came up with and just wanted to share.:)<\/p>\n<p><a href=\"http:\/\/www.amazon.com\/gp\/search?ie=UTF8&amp;keywords=java&amp;tag=extcas-20&amp;index=books&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325\">More Java Info<\/a><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.assoc-amazon.com\/e\/ir?t=extcas-20&amp;l=ur2&amp;o=1\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" style=\"border:none !important; margin:0px !important;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a java tip I discovered. Java doesn&#8217;t allow functions to return multiple parameters. You can&#8217;t pass by reference like in C\/C++. Say you have this function in C or C++: int get(int a, int* b, int* c){ *b = 2 * a; *c = 3 * a; return 4 * a;} Now you want [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","om_disable_all_campaigns":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[260],"tags":[],"class_list":["post-121","post","type-post","status-publish","format-standard","hentry","category-how-to-return-multiple-parameter-values-in-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to return multiple parameter values in Java - Zofxare Blog Home<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to return multiple parameter values in Java - Zofxare Blog Home\" \/>\n<meta property=\"og:description\" content=\"Here&#8217;s a java tip I discovered. Java doesn&#8217;t allow functions to return multiple parameters. You can&#8217;t pass by reference like in C\/C++. Say you have this function in C or C++: int get(int a, int* b, int* c){ *b = 2 * a; *c = 3 * a; return 4 * a;} Now you want [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/\" \/>\n<meta property=\"og:site_name\" content=\"Zofxare Blog Home\" \/>\n<meta property=\"article:published_time\" content=\"2007-08-17T21:59:00+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.assoc-amazon.com\/e\/ir?t=extcas-20&amp;l=ur2&amp;o=1\" \/>\n<meta name=\"author\" content=\"zofxare\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"zofxare\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/08\\\/17\\\/how-to-return-multiple-parameter-values-in-java\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/08\\\/17\\\/how-to-return-multiple-parameter-values-in-java\\\/\"},\"author\":{\"name\":\"zofxare\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#\\\/schema\\\/person\\\/094f5dde70100b9f8fbc63174a2a40ce\"},\"headline\":\"How to return multiple parameter values in Java\",\"datePublished\":\"2007-08-17T21:59:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/08\\\/17\\\/how-to-return-multiple-parameter-values-in-java\\\/\"},\"wordCount\":203,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/08\\\/17\\\/how-to-return-multiple-parameter-values-in-java\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.assoc-amazon.com\\\/e\\\/ir?t=extcas-20&amp;l=ur2&amp;o=1\",\"articleSection\":[\"How to return multiple parameter values in Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/08\\\/17\\\/how-to-return-multiple-parameter-values-in-java\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/08\\\/17\\\/how-to-return-multiple-parameter-values-in-java\\\/\",\"url\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/08\\\/17\\\/how-to-return-multiple-parameter-values-in-java\\\/\",\"name\":\"How to return multiple parameter values in Java - Zofxare Blog Home\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/08\\\/17\\\/how-to-return-multiple-parameter-values-in-java\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/08\\\/17\\\/how-to-return-multiple-parameter-values-in-java\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/www.assoc-amazon.com\\\/e\\\/ir?t=extcas-20&amp;l=ur2&amp;o=1\",\"datePublished\":\"2007-08-17T21:59:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#\\\/schema\\\/person\\\/094f5dde70100b9f8fbc63174a2a40ce\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/08\\\/17\\\/how-to-return-multiple-parameter-values-in-java\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/08\\\/17\\\/how-to-return-multiple-parameter-values-in-java\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/08\\\/17\\\/how-to-return-multiple-parameter-values-in-java\\\/#primaryimage\",\"url\":\"http:\\\/\\\/www.assoc-amazon.com\\\/e\\\/ir?t=extcas-20&amp;l=ur2&amp;o=1\",\"contentUrl\":\"http:\\\/\\\/www.assoc-amazon.com\\\/e\\\/ir?t=extcas-20&amp;l=ur2&amp;o=1\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/2007\\\/08\\\/17\\\/how-to-return-multiple-parameter-values-in-java\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to return multiple parameter values in Java\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/\",\"name\":\"Zofxare Blog Home\",\"description\":\"The Zofxare blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/#\\\/schema\\\/person\\\/094f5dde70100b9f8fbc63174a2a40ce\",\"name\":\"zofxare\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/?s=96&d=retro&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/?s=96&d=retro&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/?s=96&d=retro&r=g\",\"caption\":\"zofxare\"},\"url\":\"https:\\\/\\\/zofxare.com\\\/zofxare\\\/blog\\\/author\\\/zofxare\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to return multiple parameter values in Java - Zofxare Blog Home","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/","og_locale":"en_US","og_type":"article","og_title":"How to return multiple parameter values in Java - Zofxare Blog Home","og_description":"Here&#8217;s a java tip I discovered. Java doesn&#8217;t allow functions to return multiple parameters. You can&#8217;t pass by reference like in C\/C++. Say you have this function in C or C++: int get(int a, int* b, int* c){ *b = 2 * a; *c = 3 * a; return 4 * a;} Now you want [&hellip;]","og_url":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/","og_site_name":"Zofxare Blog Home","article_published_time":"2007-08-17T21:59:00+00:00","og_image":[{"url":"http:\/\/www.assoc-amazon.com\/e\/ir?t=extcas-20&amp;l=ur2&amp;o=1","type":"","width":"","height":""}],"author":"zofxare","twitter_card":"summary_large_image","twitter_misc":{"Written by":"zofxare","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/#article","isPartOf":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/"},"author":{"name":"zofxare","@id":"https:\/\/zofxare.com\/zofxare\/blog\/#\/schema\/person\/094f5dde70100b9f8fbc63174a2a40ce"},"headline":"How to return multiple parameter values in Java","datePublished":"2007-08-17T21:59:00+00:00","mainEntityOfPage":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/"},"wordCount":203,"commentCount":0,"image":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/#primaryimage"},"thumbnailUrl":"http:\/\/www.assoc-amazon.com\/e\/ir?t=extcas-20&amp;l=ur2&amp;o=1","articleSection":["How to return multiple parameter values in Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/","url":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/","name":"How to return multiple parameter values in Java - Zofxare Blog Home","isPartOf":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/#primaryimage"},"image":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/#primaryimage"},"thumbnailUrl":"http:\/\/www.assoc-amazon.com\/e\/ir?t=extcas-20&amp;l=ur2&amp;o=1","datePublished":"2007-08-17T21:59:00+00:00","author":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/#\/schema\/person\/094f5dde70100b9f8fbc63174a2a40ce"},"breadcrumb":{"@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/#primaryimage","url":"http:\/\/www.assoc-amazon.com\/e\/ir?t=extcas-20&amp;l=ur2&amp;o=1","contentUrl":"http:\/\/www.assoc-amazon.com\/e\/ir?t=extcas-20&amp;l=ur2&amp;o=1"},{"@type":"BreadcrumbList","@id":"https:\/\/zofxare.com\/zofxare\/blog\/2007\/08\/17\/how-to-return-multiple-parameter-values-in-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/zofxare.com\/zofxare\/blog\/"},{"@type":"ListItem","position":2,"name":"How to return multiple parameter values in Java"}]},{"@type":"WebSite","@id":"https:\/\/zofxare.com\/zofxare\/blog\/#website","url":"https:\/\/zofxare.com\/zofxare\/blog\/","name":"Zofxare Blog Home","description":"The Zofxare blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/zofxare.com\/zofxare\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/zofxare.com\/zofxare\/blog\/#\/schema\/person\/094f5dde70100b9f8fbc63174a2a40ce","name":"zofxare","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=retro&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=retro&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/?s=96&d=retro&r=g","caption":"zofxare"},"url":"https:\/\/zofxare.com\/zofxare\/blog\/author\/zofxare\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/posts\/121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/comments?post=121"}],"version-history":[{"count":0,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/posts\/121\/revisions"}],"wp:attachment":[{"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/media?parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/categories?post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zofxare.com\/zofxare\/blog\/wp-json\/wp\/v2\/tags?post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}