Java SE (JDK) – java Util Package

Image

1. Java SE ( Java Platform – Standard Edition) Is a Platform for Development and Deployment.

2. java.util.*
Java.util.* is a package provide support for the event model, collections framework, date and time facilities,and contain various utility classes.

java.util.* package contains with numbers of useful classes and interface.

2.1. Using java.util.List

– What is Java.util.List ?
answer: List is a sub interface to Collection under java.util package.It is an ordered collection:

Example code using java.util.List with Iterator

package array;
import java.util.Iterator;
import java.util.List;import java.util.Arrays;

public class iterator_utilList1 {
// How iterator work? its same like others type of loop syntax

public static void main(String[] argv) {

// set the array value – string
String stArrays[] = new String[] {“chicken”, “Dog”, “cats”,”Duck” };

//how to convert array to list? using java.util.list package
/*** what is Arrays?

– answer:An array is a container object that holds a fixed number of values of a single type. The length of an
array is established when the array is created. After creation, its length is fixed.

******/
                List<String> listOfAnimal = Arrays.asList(stArrays);

              // What is Itterator?
                        Iterator<String> iterator = listOfAnimal.iterator();
              while (iterator.hasNext()) {
                     System.out.println(iterator.next());
                    }
          }
}

 

Output:

chicken
Dog
cats
Duck

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s