I am getting a warning about unchecked unsafe operations. I am not quite sure why I am getting this warning, but does anyone know what exception I should be trying to catch and where? I am assuming that I getting this warning because I am not checking for possible exceptions.
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
public class Tokenizer{
public static String split( String string )
{
TreeSet tree = new TreeSet();
StringTokenizer tokenizer =
new StringTokenizer( string );
while ( tokenizer.hasMoreTokens() )
tree.add( tokenizer.nextToken() );
String result = tree.toString();
return result;
}//end of split
public static void main( String args[] )
{
String str;
Scanner input = new Scanner(System.in);
System.out.println("Please input a string:");
str = input.nextLine();
split(str);
}//end of main
}//end of tokenizer
Your problem is that you aren’t using generics.
You should have something like:
Or add
@SuppressWarnings("unchecked")above your method (Not recommended)Edit:
You can go here to get some more information on using generics:
https://en.wikipedia.org/wiki/Generics_in_Java