Object Class

Object Class with toArray Method

Object class is super class of all system define classes like Integer, Double, Float, String and many more. Object classes can store any types of data and then use easily.

In this blog, we will see how to store Integer object data store in Object array using toArray() method.

 

Let’s see Example on Object Class

 

import java.util.*;

class collection3

{

                public static void main(String args[])

                {

                                ArrayList<Integer> list1 = new ArrayList<Integer>();

                                list1.add(new Integer(67));

                                list1.add(new Integer(89));

                                list1.add(new Integer(45));

                                list1.add(new Integer(39));

                                list1.add(new Integer(90));

 

                                Object ob[] = list1.toArray();       // All List data now store in ob[] Array

 

                                int sum = 0;

                                for(int i=0;i<ob.length;i++)

                                {

                                                sum = sum + ((Integer)ob[i]).intValue();

                                }

                                System.out.println(“Sum = ” + sum);

                }

}

 

Output

Sum = 330

 

Video on simple Object Class Example


For more videos on Java visit our YouTube Channel


Earn Money Online

2067total visits,3visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

12 responses to “Object Class with toArray Method”

  1. Hey there! Do you know if they make any plugins to help with SEO?
    I’m trying to get my blog to rank for some targeted keywords but I’m not seeing
    very good results. If you know of any please share.

    Many thanks!

  2. Hi there would you mind stating which blog platform you’re using?
    I’m going to start my own blog soon but I’m having a difficult time making a decision between BlogEngine/Wordpress/B2evolution and Drupal.

    The reason I ask is because your design and style seems different then most blogs and
    I’m looking for something completely unique.
    P.S Sorry for getting off-topic but I had to ask!

  3. A person necessarily lend a hand to make significantly
    articles I would state. This is the first time I
    frequented your website page and so far? I surprised with the analysis you made to create this actual post incredible.
    Fantastic activity!