Unable to print the array method that returns an array

public class ReturnAtrray {
     public static void main(String[] args) {
          int[] b= {1, 3, 5};
          System.out.println(incrementArray(b,2));
     public static int[] incrementArray(int [] a, int increment)
          int[] tmp = new int[a.length];
          for(int i = 0; i <a.length; i++ )
               tmp= tmp[i] + increment;
          return tmp;     

You are correct: Java is always pass by value. In the case of an array it is a reference to the array that is passed by value. This means that there is a way to increment the array values "in place". As an alternative to what you are doing now consider:
// untested
public class ReturnAtrray {
    public static void main(String[] args)
        int[] b= {1, 3, 5};
        incrementArray(b,2);
        for(int i = 0; i < b.length; i++)
            System.out.print(b[i] + " ");
    public static void incrementArray(int [] a, int increment)
        for(int i = 0; i <a.length; i++)
            a[i] = a[i] + increment;
}

Similar Messages

  • Web Service Method that returns an ArrayList

    Hi guys,
    I have to create a web service method that returns an ArrayList, but it's not working. My problem is:
    With the "@XmlSeeAlso" annotation, my client prints the result, but the ArryaList is not from java.util, it's from org.me.calculator so I can't use it.
    If I remove this annotation, I get no result, with this error message on Tomcat 6:
    [javax.xml.bind.JAXBException: class java.util.ArrayList nor any of its super class is known to this context.]
    I'm a newbie, and trying to understand web services (I read some posts here, but didn't get the point, from its answers), but this problem I just can't figure out how to solve....
    WEb Service
    package org.me.calculator;
    import java.io.Serializable;
    import javax.jws.WebMethod;
    import javax.jws.WebParam;
    import javax.jws.WebService;
    import java.util.*;
    import java.util.ArrayList;
    import javax.xml.bind.annotation.XmlSeeAlso;
    * @author eduardo.domanski
    @WebService()
    @XmlSeeAlso({java.util.ArrayList.class}) // With this, I can see the result on client, but, the ArrayList is an org.me.calculator.ArrayList class.... Strange...
    public class CalculatorWS {
        @WebMethod(operationName = "valores")
        public ArrayList valores(@WebParam(name = "a") int a,
                           @WebParam(name = "b") int b) {
            ArrayList teste = new ArrayList();
            ArrayList a1 = new ArrayList();
            a1.add(a);
            a1.add(b);
            ArrayList a2 = new ArrayList();
            a2.add(a+b);
            a2.add(a-b);
            teste.add(a1);
            teste.add(a2);
            return  teste; 
    }CLient
    package org.me.calculator.client;
    import java.io.*;
    import java.net.*;
    import java.util.ArrayList;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ClientServlet extends HttpServlet {
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet ClientServlet</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet ClientServlet at " + request.getContextPath() + "</h1>");
            try { // Call Web Service Operation
                org.me.calculator.CalculatorWSService service = new org.me.calculator.CalculatorWSService();
                org.me.calculator.CalculatorWS port = service.getCalculatorWSPort();
                // TODO initialize WS operation arguments here
                int i = 8;
                int j = -6;
                // TODO process result here
                ArrayList result = (ArrayList) port.valores(i, j);
                out.println("Result = " + result);
            } catch (Exception ex) {
                System.out.println(ex);
            // TODO handle custom exceptions here
            out.println("</body>");
            out.println("</html>");
            out.close();
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
    }THank you all,
    Eduardo
    Edited by: EduardoDomanski on Apr 23, 2008 4:40 AM

    I forgot to say that, when I try to return an ArrayList of an object, for example, ClassA, which is on the package org.me.classes, on my Server App, the ArrayList is returned, but the objects are from type org.me.calculator.ClassA. It should be from org.me.classes.ClassA, right?
    This package also exists on my client App, to use the object, but as the returned type is from another package, I can't even cast it. I tried some annotations @Xml... but it failed.
    Packages
    ServerApp
    org.me.calculator
    CalcWS.java
    org.me.classes
    ClassA.java
    Client App
    org.me.classes
    ClassA.java
    The return from my method should be an ArrayList of org.me.classes.ClassA, but when I print it, on client, it's from org.me.calculator.ClassA.
    Does anybody knows, or had the same problem?
    Thanks,
    Eduardo

  • Unable to print the report after SP2 (CR 2008 / VS 2008)?

    I'm developing an ASP.NET application using VS 2008 (Framework 3.5). I have installed CR 2008 with SP (0, 1, and 2).
    I created an invoice report and I printed it as test for the report and it works okay. I needed to change the page size of the report to a user defined size and reset all of the margins to zero.
    After I did that I was unable to print the report again and every time I tried to print the report nothing gets printed.
    I checked my environment to find the cause of this problem but I found nothing except that I'm using CR runtime for SP1 and I'm currently using SP2. So I did remove CR runtime for SP1 and install CR runtime for SP2.
    The problem didn't go away and I faced one more problem.
    Usually I'm using a dataset as a data source for my reports. After installing the CR runtime for SP2 I couldn't see any date column in my report data source (Dataset). All other types of columns appear except date fields! Why I have no Idea?
    After I do some more testing regarding my issue I found out the following
    1.     When I add a new report to my web application and I don't change the page setting the report work fine.
    2.     When I change the page setup settings (Page Margins, horizontal width and vertical height) the report show up okay but never gets printed.
    Why I don't know?
    Addition to that the report dataset (Data Source) showing in the field explorer never shows any date type field?
    All of the above issues happened with me after installing SP2.
    OS: WindowsXP Pro SP3
    CR 2008 (SP 0, 1, 2)
    VS 2008 SP1
    Please I need your help.
    Edited by: Sami Aljafer on Oct 12, 2009 8:35 PM
    Edited by: Sami Aljafer on Oct 12, 2009 8:38 PM

    Hi, Sami;
    Are you printing from the Crystal preview window, or in code?
    If you are printing from the preview window, try printing via code, such as:
    An example of print to printer:
    crReportDocument = New ReportDocument
    crReportDocument.Load("h:\labels2.rpt")
    ''Use error handling in case an error occurs
    Try
    ''Set the printer name to print the report to. By default the sample
    ''report does not have a defult printer specified. This will tell the
    ''engine to use the specified printer to print the report. Print out
    ''a test page (from Printer properties) to get the correct value.
    crReportDocument.PrintOptions.PrinterName = "
    dwcb12003\ZDesigner ZM400 200 dpi (ZPL)"
    ''Start the printing process. Provide details of the print job
    ''using the arguments.
    crReportDocument.PrintToPrinter(1, True, 1, 1)
    Please post your question about the dataset as a new post.
    Regards,
    Jonathan
    Edited by: Jonathan Parminter on Oct 12, 2009 2:28 PM

  • Calling a method that returns values in a map - using JSTL

    Hi I have a method within an object that returns a List for a particular category
    public List<String> getFieldsInCategory(String categoryName){
        return _categoryFieldsMap.get(categoryName); //This is a map that returns a list                                                             
      }Trying to call the above function in jsp, the object is available as "document",
    how do i pass a key to the above function to return a List.
       <c:forEach items="${document.fieldsInCategory('ABSTRACT')}" var="temp">How do i get the list by passing a string key to my method,
    please let me know how to go about this.
    Thanks

    JSTL can not directly call methods that take parameters.
    All it can do is access javabean properties - ie via the revealed get/set methods.
    You can fudge it by having a seperate variable to set:
    Map  _categoryFieldsMap;
    String category = null;
    public void setCategory(String category){
      this.category = category;
    public String getCategory(String category){
      return category;
    public List<String> getFieldsInCategory(){
        return _categoryFieldsMap.get(categoryName); //This is a map that returns a list                          
      }You would then do it like this in your JSP:
    <c:set target="document.category" value="ABSTRACT"/>
    <c:forEach items="${document.fieldsInCategory}" var="temp">
    ...The other alternative is to return the entire map to the page.
    EL accesses maps quite handily.
    so given a method that returns the map:
    public Map getCategoryFieldsMap(){
    return _categoryFieldsMap;
    then the expression: ${document.categoryFieldsMap.ABSTRACT} returns what you are after.
    Hope this helps,
    evnafets

  • How to code a method that returns string for class object

    I have a class named Address.
    public class Addresss{   
    private String street;   
    private String city;            // instance variables  
    private String zipcode;}I have been asked to write a method that returns a string for Address object. I dont understand how to create address object.Can anyone pls help me understand.
    do I have to write (for creating object)
    Address addressObject  = new Address(); ( coding method that returns a string for address object) ---> I really dont understand this part.

    looks almost right. The problem is that your method name AddressBookEntry does not match the name of your class AddressBook and therefore is not a constructor.
    Furthermore, you probably need to make a distinction between a single entry into the address book which consists of a single name and a single address, (which is just what you have done) and an address book itself which is probably a list of AddressBookEntries
    So for your code I would change the class that you called "AddressBook" to "AddressBookEntry" and have a third class that represents the collection of AddressBookEntries.
    Now to be honest, I don't know why you keep the name split apart from the street address portion of the address. I would be more inclined to keep the name as a field of the address itself, but it's your code, you carve it up the way you like.

  • Still after 1 week I am unable to print the HP Crossword Puzzle. When will this be resolved?

    After more than 1 week of attempting I am still unable to print the HP Crossword daily puzzle. What is going on with the fix???

    Hello Chowguy,
    I hope you are not having this issue anymore.  An update came out in the middle of May that should have fixed this issue.  If you are still having a problem, let me know and I will see what I can do to help.
    -------------How do I give Kudos? | How do I mark a post as Solved? --------------------------------------------------------

  • With my new version of numbers it is not possible to print the celnumbers. That is difficult for my bookkeeping.

    with my new version of numbers it is not possible to print the celnumbers. That is difficult for my bookkeeping.
    How to solve this problem?

    Hi Jaspers,
    A Header Row and a Header Column might work for you
    Or two extra Tables to show the Row and Column labels
    Regards,
    Ian.

  • Unable to print the document thru Crystal Integration

    Hi All,
    Could anybody help me on the issue given below.
    One of our client Issue while printing from crystal Integration in SAP Business One. I can able to view the crystal report through Crystal Integration but i am unable to print the document.No Error is getting displayed .If i am printing from PLD it's working fine .After exporting to PDF from crytal integration i can able to Print but not able to print directly from the crystal Integration.
    Thanks,
    Vishwanath

    Hi,
    Please try to post in the Integration forum have some answers there.
    Regards,
    Clint

  • Why can't i print the e-book that i purchased?

    why can't i print the e-book that i purchased?

    The print permission might not be available for that book. In Library mode, right click on the book and select Item Info. Verify whether book had print permission.
    These permissions are set at the server level by the distributor.

  • Unable to print the TDS certificates

    Dear all,
    I am running j1inmis(tds process) this year(2008 to 2009) instead of lost year(2007 to 2008).
    I have done challana update status and bank challan update status.
    i was unable to print the tds certificates.
    could you update ur valuable  inputs
    Regards
    Raju.k

    Dear all,
    Thanks for early response.
    I have given everything correctly.
    My question is
    Is it possible to run previous year process in this year?
    Could you please update your valuable inputs.
    Regards
    Raju.k

  • Hello, i ordered 2 32GB white iphone 4s online as a guest user. The mobiles has been delivered, but i cant print the invoice for that. They ask me to login with the apple ID. But as i mentioned i logged in as guest so there's no AppleID associated. HELP !

    Hello, i ordered 2 32GB white iphone 4s online as a guest user. The mobiles has been delivered, but i cant print the invoice for that. They ask me to login with the apple ID. But as i mentioned i logged in as guest so there's no AppleID associated. HELP !

    Contact Apple customer support via the "Contact Us" link at the bottom, they may be able to assist you.

  • Unable to print the entire document, how do I print the entire document?

    Unable to print the entire document, how can I fix this and get the entire document printed?

    Please provide some details; without it, nobody can possibly answer your question.

  • HT1349 how do i print the bonus booklets that come with some albums i have purchased

    how do i print the bonus books that come with some albums i purchased?

    I have a Mac so I tried this. I opened the booklet outside of iTunes and the app that opened it, has a print option.
    These digital booklets are simply PDF files and Adobe makes an app that can open them and print them and it is free to use.

  • Calling a method that returns an object Array

    Hello.
    During a JNICALL , I wish to call a method which returns an object array.
    ie my java class has a method of the form
    public MyObject[] getSomeObjects(String aString){
    MyObject[] theObjects=new MyObject[10];
    return theObjects
    Is there an equivalent to (env)->CallObjectMethod(...
    which returns a jobjectArray instead of a jobject, and if not could somebody suggest a way around this.
    Thanks,
    Neil

    I believe an array oj jobjects is also a jobject. You can then cast it to another class.

  • I am unable to print the full content of a text box within a PDF that was emailed to me - help!

    I open the pdf in Adobe Reader, and can see all of the content on screen by scrolling within the text boxes. But, because the content is "bigger" than the text box in some cases, when I print the pdf, the text gets truncated. Can I print in a way that allows me to see all text that the user entered?
    Thanks in advance for any guidance.

    Quit Safari.
    Open the Library folder in your home folder as follows:
    ☞ If running OS X 10.7 or later, hold down the option key and select Go ▹ Library from the Finder menu bar.
    ☞ If running an older version of OS X, select Go ▹ Go to Folder… from the Finder menu bar and copy the line below into the text box that opens:
    ~/Library
    Delete the following items from the Library folder:
    Caches/com.apple.Safari/Cache.db
    Preferences/com.apple.quicktime.plugin.preferences.plist
    Preferences/QuickTime Preferences
    Relaunch Safari and test.
    Launch the Console application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ If you’re running OS X 10.7 or later, open LaunchPad. Click Utilities, then Console in the page that opens.
    Select "/var/log/cups/error_log" from the file list. Post the messages from the time of the last printing attempt.
    Post the log text, please, not a screenshot. If there are runs of repeated messages, post only one example of each. Don’t post many repetitions of the same message.

Maybe you are looking for

  • How to access an External LDAP on a weblogic server using OPSS APIs.

    Hi, Can anyone let me know how I can access an External LDAP configured on a weblogic server using OPSS APIs( or alternative APIs). I'm currently using the below snippet and I'm getting only the Users and groups from the DefaultAutheticator on the we

  • Why is the "other" on my iphone take up so much space?

    Why is the "other" on my iphone take up so much space?

  • Reg : Check boxes

    Hi Experts , Im Having 3 select-options on my selection screen !! after that im having 3 check boxes.. first checkbox default it wil be selected. Now My query is ?? 1. when i execute default the first check box & process has to be exexute ? 2. pls gi

  • Error installing olaptrain sample schema for OLAP Cubes

    I want to install olaptrain schema for OLAP cubes. It has been the error when I apply the procedures. My password is also correct. This error is attachment link. http://1ercanyagmur9.blogspot.com.tr/2014/01/error.html

  • Text moves on publish

    Since updating to 2014.0.1.30 my design and preview/publish sites don't match up. Tested with Firefox, IE and Chrome. When preview or publish, the text moves to the right of the screen. The text is not pinned or anything. Everything works fine when p