Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-24-2012, 02:06 PM   PM User | #1
SteveNoob
New to the CF scene

 
Join Date: Mar 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
SteveNoob is an unknown quantity at this point
unchecked or Unsafe operations

Hey, This is a small java program for sorting user input into a vector it, sorts and outputs. Im a newbie but it works although it flash a warning
program.java uses unsafe or unchecked operations.
recompile with -XLint: unchecked for details.

Its not the end of the world but this is homework so i can see me getting slated for it.

Code:
import java.util.Vector;
import java.util.Collections;
import javax.swing.JOptionPane;
public class VectorSort {

public static void main(String[] args) {


Vector v = new Vector();
String userInput;
for (int i= 0; i<= 5; i++)
{ 
userInput = JOptionPane.showInputDialog(null, "Enter words to be sorted now:");

v.add(userInput);
}


Collections.sort(v);
JOptionPane.showMessageDialog(null, "Vector elements after sorting : ");
for(int j=0; j<v.size(); j++)
JOptionPane.showMessageDialog(null, v.get(j));

}
}
SteveNoob is offline   Reply With Quote
Old 03-24-2012, 05:50 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,751
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
If you have not yet been taught generics, then you can safely ignore the errors.
The problem is that Vector/Collections are generic types, so you should specify what type of object is allowed within them: Vector<String> v = new Vector<String>();.
If generics have not been covered, I believe the supressWarnings options work at a compiler level. Add this immediately above the method signature:
Code:
@SuppressWarnings({ "rawtypes", "unchecked" })
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:33 PM.


Advertisement
Log in to turn off these ads.