Java program for changeable wrapper class
By: Issac Printer Friendly Format
In this tutorial we are going to see a changeable wrapper class example. In this example We have file named MainClass.java.. Here we want arraylist, list. So we have to import util package.We can use import java.util.ArrayList; , import java.util.List; in this example..
import java.util.ArrayList;
import java.util.List;
class Values {
private int s;
public Values(int x)
{
s = x;
}
public int getNumber()
{
return s;
}
public void setNumber(int s)
{
this.s = s;
}
public void increment()
{
s++;
}
public String toString()
{
return Integer.toString(s);
}
}
public class MainClass
{
public static void main(String[] args)
{
List list = new ArrayList();
for (int i = 0; i < 10; i++)
list.add(new Values(i));
System.out.println(list);
for (int i = 0; i < list.size(); i++)
((Values) list.get(i)).increment();
System.out.println(list);
}
}
Output:
[0,1,2,3,4,5,6,7,8,9]
[1,2,3,4,5,6,7,8,9,10]
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Subscribe to Tutorials
Related Tutorials
Program using concept of byte long short and int in java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java