473,405 Members | 2,176 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Warning in java : unchecked or unsafe operation

17
import java.util.ArrayList;
import java.util.Iterator;


public class collectionsremove
{

public static void main(String[] args)
{


ArrayList arr = new ArrayList();
String str1 = "hi";
arr.add(str1);
arr.add("hello");
arr.add("wassup");
arr.add("wazzup");
arr.add("bye");



Iterator it = arr.iterator();

while(it.hasNext() )
{

it.next();
it.remove();
}
}
}

}



when i compile this code i get warning as :
collectionsremove.java use unchecked or unsafe operation
recompile with -Xlint : unchecked for detail


how to remove this warning .

anyhow my program runs fine , how to remove
Jan 9 '08 #1
3 7519
JosAH
11,448 Expert 8TB
Starting at Java 1.5 the Java language implements 'generics', i.e. a type can be
specified using another type. This is all a compilation feature and the Java virtual
machine didn't change for that. You are using the 'raw' type of ArrayList and the
compiler warns you for it (you can stick any type on a raw List). After compilation
has finished the 'type erasure' mechanism sets in; it doesn't do anything, it just
uses the raw type where you had specified a generic type.
This is how you define a List that stores Strings:

Expand|Select|Wrap|Line Numbers
  1. List<String> list= new ArrayList<String>();
  2.  
You can use that 'list' to store and remove Strings in/from it and the compiler will
keep its mouth shut. If you want to store a different type in your list the compiler
will heavily complain to you.

kind regards,

Jos
Jan 9 '08 #2
BigDaddyLH
1,216 Expert 1GB
Here are two tutorials you may find useful:

Collections tutorial (using generics)

Generics tutorial
Jan 9 '08 #3
JosAH
11,448 Expert 8TB
Also have a look at this Wikipedia page. It has some fine external references.

kind regards,

Jos
Jan 9 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: kathyk | last post by:
Hi All, We are moving to Access 2003 in a month or so, so i started testing my data base files in v2003. When The mdb open I get 3 warning messagase about blocking unsafe expressions. Security...
3
by: Andre | last post by:
if I have an unsafe method that takes in two arrays, performs some operations and returns; I know that the garbage collector will not collect objects allocated inside the unsafe method. However, if...
4
by: Patrick Olurotimi Ige | last post by:
Huge security hole in .NET: Java creator http://www.zdnet.com.au/news/security/0,2000061744,39179932,00.htm *** Sent via Developersdex http://www.developersdex.com *** Don't just participate...
11
by: zeppe | last post by:
Hi all, I've a problem. The code that follows creates a warning in both gcc and visual c++. However, I think it's correct: basically, there is a function that return an object of a derived...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
17
by: B. Williams | last post by:
I am receiving two warnings in my code and can't figure out why. Will someone look at this and tell me what I have done wrong? #include <iostream> using std::cout; #include <string> ...
3
by: Vittorix | last post by:
Hi all, I'm talking about of the following warning: "myClass.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details." Usually when this warning occours...
3
oll3i
by: oll3i | last post by:
i m trying to write a hello world server but i get the following 3 errors cd u please help me javac HelloServer.java HelloApp/*.java HelloServer.java:52: cannot find symbol symbol: class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.