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 3 of 3

Thread: syntax question

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default syntax question

    lets say i have a string object...this string object holds 3 separate "future" int data types...which i can easily "tokenize" and then convert to an int for a variable to hold.

    ex. "25 5 500"

    question is...how can i access say the int of 500 from this string object in one statement so I am able to compare it to another int variable?

    String line = "25  5  500";
    new String(line);  //string object created 
     
    st = new StringTokenizer(line, " ");
                while(st.hasMoreTokens()){
                    String arr = st.nextToken();
                    String p = st.nextToken();
                    String cpu = st.nextToken();
                    int arrival = Integer.parseInt(arr.trim());
                    int pid = Integer.parseInt(p.trim());
                    int cputime = Integer.parseInt(cpu.trim());       
                }

    arrival = 25
    pid = 5
    cputime = 500
    Last edited by surfbumb; March 9th, 2011 at 03:27 PM.


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

    Default Re: syntax question

    Not sure I understand the question...you are accessing the 3rd int value in the 'cputime' variable and can just use the == to compare to another int

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: syntax question

    eh nevermind it was a design issue.

Similar Threads

  1. Replies: 3
    Last Post: February 22nd, 2011, 08:43 PM
  2. How do you read this syntax?
    By meowCat in forum Java Theory & Questions
    Replies: 5
    Last Post: August 8th, 2010, 03:09 PM
  3. New Syntax Highlighting Feature!
    By JavaPF in forum Forum Updates & Feedback
    Replies: 15
    Last Post: July 14th, 2010, 09:20 AM