Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: unsafe operations note??

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default unsafe operations note??

    import java.util.*;
     
    public class iterates {
     
        private ArrayList<String> arrayOfString = new ArrayList();
        private String input = "hui hello { q...} qdf qkfh youu";
        private int n = 0;
     
        public static void main(String[] args) {
            iterates h = new iterates();
            h.studyString();
        }
     
        public void studyString() {
            String originalText = "Hello ther{e oops)eee";
            arrayOfString = toArray(originalText);
            Iterator bitch = arrayOfString.iterator();
     
            while (bitch.hasNext()) {
                if (bitch.next().equals('{') || bitch.next().equals('}')) {
                    int i = arrayOfString.indexOf(bitch.next());
                    arrayOfString.add(i + 1, "<br>");
                }
            }
     
        }
     
        public ArrayList<String> toArray(String input) {
            StringTokenizer pieces = new StringTokenizer(input);
     
     
            while (n <= pieces.countTokens()) {
                arrayOfString.add(n, pieces.nextToken());
            }
            n++;
     
            return arrayOfString;
        }
    }
    Upon compiling this, I get the note "iterates.java uses unchecked or unsafe operations"; "Recompile with -Xlint: unchecked for details". How can I resolve this?

    Note, I am trying to convert a random string (the code here has been slightly adjusted - this is in fact a stub of a class) to an arrayList<String>. If you have a better idea as to how I should do this, please let me know!

    Thanks!
    Last edited by helloworld922; March 20th, 2010 at 06:07 PM.


  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: unsafe operations note??

    SO SORRRYYYY FOR THE DEROGATORY VARIABLE NAMESSSSSSSSS! I THOUGHT I READJUSTED BEFORE COPY PASTING. IT'S ME EXPRESSING THE FRUSTRATION :p! SORRY ONCE AGAIN!

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: unsafe operations note??

    Check the use of Generics in your code, for example:

    private ArrayList<String> arrayOfString = new ArrayList[COLOR="SeaGreen"]<String>[/COLOR]();

    You can also use the split function of String

    String[] split = inputString.split("\t\n\r\f");
    Which splits on the default delim for StringTokenizer and returns an array

  4. #4
    Junior Member
    Join Date
    Mar 2010
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: unsafe operations note??

    Thanks once again copeg.

    If I apply your split method, it will "deform" the string so that when I come to convert the ArrayList back into a string, the white space will be missing (if I initially use that as a delimiter?)

    And what exactly is String[]...a form of array list no? so how exactly do I instantiate this in the beginning of the code?

Similar Threads

  1. Bulk operations on sets/ map problem
    By kyuss in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 14th, 2010, 12:48 PM