Why doesn t importing java util include Arrays and Lists

0 votes

I am using java on debian 5

java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

Why is there a difference between the following

Case 1:

import java.util.*;

Case 2:

import java.util.*;
import java.util.Arrays;
import java.util.List;

Why doesnt the first case cover the second case?

The code only compiles when I import Arrays and List explicitly.

Code:

import java.util.*;
import java.util.Arrays;
import java.util.List;

public class Test {
        public static void main (String[] args) {
                List<Integer> i = new ArrayList(Arrays.asList(1,2,3,4,5,6,7,8,9,10));
                List<Integer> j = new ArrayList();
                ListIterator<Integer> n = i.listIterator(i.size());

                while(n.hasPrevious()) {
                        j.add(n.previous());
                }

                println(j);

        }

        static void println(Object o) {
                System.out.println(o);
        }

        static void print(Object o) {
                System.out.print(o);
        }

}

The error I get when I comment out the 2nd and 3rd import statements are:

nattyp@debian:~/dev/java$ javac Test.java
Test.java:7: cannot find symbol
symbol  : method asList(int,int,int,int,int,int,int,int,int,int)
location: class Arrays
                List<Integer> i = new ArrayList(Arrays.asList(1,2,3,4,5,6,7,8,9,10));
                                                      ^
Note: Test.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
nattyp@debian:~/dev/java$
Nov 16, 2022 in Java by Ashwini
• 5,430 points
734 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Java

0 votes
1 answer

Why there is the need of getters and setters in java

In Java getters and setters are completely ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,290 points
1,964 views
0 votes
2 answers

Converting between java.time.LocalDateTime and java.util.Date

Try this: Date in = new Date(); LocalDateTime ldt ...READ MORE

answered Aug 27, 2019 in Java by Sirajul
• 59,230 points
2,889 views
0 votes
0 answers
0 votes
0 answers

why so JavaScript and java have similar name

Nov 29, 2023 in Java by Priyanka
• 4,080 points
707 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,220 points
3,578 views
0 votes
2 answers

How do I get the current date and time using Java?

If you require a time stamp in ...READ MORE

answered Aug 23, 2019 in Java by Sirajul
• 59,230 points
2,933 views
0 votes
0 answers

Exception in thread "main" java.lang.Error: Unresolved compilation problems

I am facing issues importing classes and ...READ MORE

May 7, 2022 in Java by narikkadan
• 63,600 points
5,524 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 81,223 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
8,358 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
17,433 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP