Solved

Add value to a list

Posted on 2013-06-14
2
236 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 86
github account with ecipse 1 47
tomcat not starting 6 45
How to convert from xls to xlsx using java 7 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…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

772 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