Solved

Add value to a list

Posted on 2013-06-14
2
237 Views
Last Modified: 2013-06-17
How would I write a statement to add the value to the list.


    public ItemVO getItems (List<ItemVO > XItems, String
                                            test
      {
          List<ItemVO> resultList;
            
          for (ItemVO vo : XItems)
          {
               If vo.getName = test
              {
                // add vo to resultList  HOW WOULD I write this statement to add to list
              }  
          }  
 
            return resultList;
      }
0
Comment
Question by:cookiejar
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39249243
You need to instantiate your list first of all:

List<ItemVO> resultList = new ArrayList<ItemVO>();

Open in new window


Then it would be a matter of calling the add method.

e.g.

if (vo.getName == test)
{
    resultList.add(vo);
}   

Open in new window

0
 
LVL 21

Expert Comment

by:Amitkumar Panchal
ID: 39250131
Agree with kaufmed
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
web services creation SOAP vs REST 5 57
Java Restore security prompts not working 10 73
Java: The Public Class Main 4 32
Bot application - advice 3 39
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question