Replace? String.getBytes(int�begin, int�end, byte[]�dst, int�dbegin)

how do you replace something like this? even if you go through characters, the deprecations notes say that goin through character arrays is wrong, right? if you just use String.getBytes() then you get them all and you can specify the parts you want...any ideas?

so far i have this:
    tmp = newData.getBytes();
               for (int t=0;t<toCopy;t++) {
                    buffer[offset + t] = tmp[t];
seems klunky...

Similar Messages

  • Replacing String month with type Int - What to do!?!

    import java.util.Scanner;
    public class Date
        private String month;
        private int day;
        private int year; //a four digit number.
        public Date( )
            month = "January";
            day = 1;
            year = 1000;
        public Date(int monthInt, int day, int year)
            setDate(monthInt, day, year);
        public Date(String monthString, int day, int year)
            setDate(monthString, day, year);
        public Date(int year)
            setDate(1, 1, year);
        public Date(Date aDate)
            if (aDate == null)//Not a real date.
                 System.out.println("Fatal Error.");
                 System.exit(0);
            month = aDate.month;
            day = aDate.day;
            year = aDate.year;
        public void setDate(int monthInt, int day, int year)
            if (dateOK(monthInt, day, year))
                this.month = monthString(monthInt);
                this.day = day;
                this.year = year;
            else
                System.out.println("Fatal Error");
                System.exit(0);
        public void setDate(String monthString, int day, int year)
            if (dateOK(monthString, day, year))
                this.month = monthString;
                this.day = day;
                this.year = year;
            else
                System.out.println("Fatal Error");
                System.exit(0);
        public void setDate(int year)
            setDate(1, 1, year);
        public void setYear(int year)
            if ( (year < 1000) || (year > 9999) )
                System.out.println("Fatal Error");
                System.exit(0);
            else
                this.year = year;
        public void setMonth(int monthNumber)
            if ((monthNumber <= 0) || (monthNumber > 12))
                System.out.println("Fatal Error");
                System.exit(0);
            else
                month = monthString(monthNumber);
        public void setDay(int day)
            if ((day <= 0) || (day > 31))
                System.out.println("Fatal Error");
                System.exit(0);
            else
                this.day = day;
        public int getMonth( )
            if (month.equals("January"))
                return 1;
            else if (month.equals("February"))
                return 2;
            else if (month.equalsIgnoreCase("March"))
                return 3;
            else if (month.equalsIgnoreCase("April"))
                return 4;
            else if (month.equalsIgnoreCase("May"))
                return 5;
            else if (month.equals("June"))
                return 6;
            else if (month.equalsIgnoreCase("July"))
                return 7;
            else if (month.equalsIgnoreCase("August"))
                return 8;
            else if (month.equalsIgnoreCase("September"))
                return 9;
            else if (month.equalsIgnoreCase("October"))
                return 10;
            else if (month.equals("November"))
                return 11;
            else if (month.equals("December"))
                return 12;
            else
                System.out.println("Fatal Error");
                System.exit(0);
                return 0; //Needed to keep the compiler happy
        public int getDay( )
            return day;
        public int getYear( )
            return year;
        public String toString( )
            return (month + " " + day + ", " + year);
        public boolean equals(Date otherDate)
            return ( (month.equals(otherDate.month))
                      && (day == otherDate.day) && (year == otherDate.year) );
        public boolean precedes(Date otherDate)
            return ( (year < otherDate.year) ||
               (year == otherDate.year && getMonth( ) < otherDate.getMonth( )) ||
               (year == otherDate.year && month.equals(otherDate.month)
                                             && day < otherDate.day) );
        public void readInput( )
            boolean tryAgain = true;
            Scanner keyboard = new Scanner(System.in);
            while (tryAgain)
                System.out.println("Enter month, day, and year.");
                  System.out.println("Do not use a comma.");
                String monthInput = keyboard.next( );
                int dayInput = keyboard.nextInt( );
                int yearInput = keyboard.nextInt( );
                if (dateOK(monthInput, dayInput, yearInput) )
                    setDate(monthInput, dayInput, yearInput);
                    tryAgain = false;
                else
                    System.out.println("Illegal date. Reenter input.");
        private boolean dateOK(int monthInt, int dayInt, int yearInt)
            return ( (monthInt >= 1) && (monthInt <= 12) &&
                     (dayInt >= 1) && (dayInt <= 31) &&
                     (yearInt >= 1000) && (yearInt <= 9999) );
        private boolean dateOK(String monthString, int dayInt, int yearInt)
            return ( monthOK(monthString) &&
                     (dayInt >= 1) && (dayInt <= 31) &&
                     (yearInt >= 1000) && (yearInt <= 9999) );
        private boolean monthOK(String month)
            return (month.equals("January") || month.equals("February") ||
                    month.equals("March") || month.equals("April") ||
                    month.equals("May") || month.equals("June") ||
                    month.equals("July") || month.equals("August") ||
                    month.equals("September") || month.equals("October") ||
                    month.equals("November") || month.equals("December") );
        private String monthString(int monthNumber)
            switch (monthNumber)
            case 1:
                return "January";
            case 2:
                return "February";
            case 3:
                return "March";
            case 4:
                return "April";
            case 5:
                return "May";
            case 6:
                return "June";
            case 7:
                return "July";
            case 8:
                return "August";
            case 9:
                return "September";
            case 10:
                return "October";
            case 11:
                return "November";
            case 12:
                return "December";
            default:
                System.out.println("Fatal Error");
                System.exit(0);
                return "Error"; //to keep the compiler happy
    }My question is that if I were to change the String month in the instance variables to type int, what changes do I make to the code to make this work WITHOUT changing the method headings and it also says that none of the type String paraenters should change to type int. I need to redefine the methods to make it work. I've been at this for hours and am just stuck so this is the reason for my early morning post.

    import java.util.Scanner;
    public class Date
        private int month;
        private int day;
        private int year; //a four digit number.
        public Date( )
            month = 1;
            day = 1;
            year = 1000;
        public Date(int monthInt, int day, int year)
            setDate(monthInt, day, year);
        public Date(String monthString, int day, int year)
            setDate(monthString, day, year);
        public Date(int year)
            setDate(1, 1, year);
        public Date(Date aDate)
            if (aDate == null)//Not a real date.
                 System.out.println("Fatal Error.");
                 System.exit(0);
            month = aDate.month;
            day = aDate.day;
            year = aDate.year;
        public void setDate(int monthInt, int day, int year)
            if (dateOK(monthInt, day, year))
                this.month = monthInt;
                this.day = day;
                this.year = year;
            else
                System.out.println("Fatal Error");
                System.exit(0);
        public void setDate(String monthString, int day, int year)
            if (dateOK(monthString, day, year))
                this.month = monthStringToInt(monthString);
                this.day = day;
                this.year = year;
            else
                System.out.println("Fatal Error");
                System.exit(0);
        public void setDate(int year)
            setDate(1, 1, year);
        public void setYear(int year)
            if ( (year < 1000) || (year > 9999) )
                System.out.println("Fatal Error");
                System.exit(0);
            else
                this.year = year;
        public void setMonth(int monthNumber)
            if ((monthNumber <= 0) || (monthNumber > 12))
                System.out.println("Fatal Error");
                System.exit(0);
            else
                month = monthNumber;
        public void setDay(int day)
            if ((day <= 0) || (day > 31))
                System.out.println("Fatal Error");
                System.exit(0);
            else
                this.day = day;
        public int getMonth( )
             return month;
        public int getDay( )
            return day;
        public int getYear( )
            return year;
        public String toString( )
            return (month + " " + day + ", " + year);
        public boolean equals(Date otherDate)
            return ( (month == otherDate.month)
                      && (day == otherDate.day) && (year == otherDate.year) );
        public boolean precedes(Date otherDate)
            return ( (year < otherDate.year) ||
               (year == otherDate.year && getMonth( ) < otherDate.getMonth( )) ||
               (year == otherDate.year && month == otherDate.month
                                             && day < otherDate.day) );
        public void readInput( )
            boolean tryAgain = true;
            Scanner keyboard = new Scanner(System.in);
            while (tryAgain)
                System.out.println("Enter month, day, and year.");
                  System.out.println("Do not use a comma.");
                String monthInput = keyboard.next( );
                int dayInput = keyboard.nextInt( );
                int yearInput = keyboard.nextInt( );
                if (dateOK(monthInput, dayInput, yearInput) )
                    setDate(monthInput, dayInput, yearInput);
                    tryAgain = false;
                else
                    System.out.println("Illegal date. Reenter input.");
        private boolean dateOK(int monthInt, int dayInt, int yearInt)
            return ( (monthInt >= 1) && (monthInt <= 12) &&
                     (dayInt >= 1) && (dayInt <= 31) &&
                     (yearInt >= 1000) && (yearInt <= 9999) );
        private boolean dateOK(String monthString, int dayInt, int yearInt)
            return ( monthOK(monthString) &&
                     (dayInt >= 1) && (dayInt <= 31) &&
                     (yearInt >= 1000) && (yearInt <= 9999) );
        private boolean monthOK(String month)
            return (month.equals("January") || month.equals("February") ||
                    month.equals("March") || month.equals("April") ||
                    month.equals("May") || month.equals("June") ||
                    month.equals("July") || month.equals("August") ||
                    month.equals("September") || month.equals("October") ||
                    month.equals("November") || month.equals("December") );
        private String monthString(int monthNumber)
            switch (monthNumber)
            case 1:
                return "January";
            case 2:
                return "February";
            case 3:
                return "March";
            case 4:
                return "April";
            case 5:
                return "May";
            case 6:
                return "June";
            case 7:
                return "July";
            case 8:
                return "August";
            case 9:
                return "September";
            case 10:
                return "October";
            case 11:
                return "November";
            case 12:
                return "December";
            default:
                System.out.println("Fatal Error");
                System.exit(0);
                return "Error"; //to keep the compiler happy
        private int monthStringToInt(String monthString) {
             if (monthString.equals("January")) return 1;
             else if (monthString.equals("February")) return 2;
             else if (monthString.equals("March")) return 3;
             else if (monthString.equals("April")) return 4;
             else if (monthString.equals("May")) return 5;
             else if (monthString.equals("June")) return 6;
             else if (monthString.equals("July")) return 7;
             else if (monthString.equals("August")) return 8;
             else if (monthString.equals("September")) return 9;
             else if (monthString.equals("October")) return 10;
             else if (monthString.equals("November")) return 11;
             else if (monthString.equals("December")) return 12;
             else return -1;
    }I've added one method: monthStringToInt to convert "January", "February" into an integer value. There are probably better ways to do this (Calendar), but this involes no other classes.

  • Removing punctuation from the beginning and end of a string

    I am working on a project for a "spell checking" program. So far the StringHash class is made, and the dictionary is read into a hash table. Then the document to be checked is specified via command line, the document scans through each word and checks to see if it is in the dictionary, if it is do nothing, if it is not then display it to console. The problem I am having is with a method in the main class. The method (I will post what I have so far) is called removePunct. The method should remove any punctuation from the beginning and the end of the string, nothing from the middle. Here is what I have so far:
    public static String removePunct(String word){
              StringBuilder wo = new StringBuilder(word);
              int x = (word.length()-1);
              if(!Character.isLetter(wo.charAt(0)))
                   wo.deleteCharAt(0);
              if(!Character.isLetter(wo.charAt(x)))
                   wo.deleteCharAt(x);
              return wo.toString();
    Any help would be much appreciated, I'm pretty certain the solution is either something completely different, or something so simple that I just missed it.

    The easiest way to do this is to just show you the actual file to be spell checked:
    -- outline --
    This directory contains Bison skeletons: the general shapes of the
    different parser kinds, that are specialized for specific grammars by
    the bison program.
    Currently, there are only three supported skeletons:
    - yacc.c
    It used to be named bison.simple: it corresponds to C Yacc
    compatible LALR(1) parsers.
    - lalr1.cc
    Produces a C++ parser class. It is still very experimental, and not
    yet supported. Please, subscribe to [email protected].
    - glr.c
    A Generalized LR C parser based on Bison's LALR(1) tables.
    These skeletons are the only ones supported by the Bison team.
    Because the interface between skeletons and the bison program is not
    finished, we are not bound to it. In particular, Bison is not
    mature enough for us to consider that ``foreign skeletons'' are
    supported.
    Copyright (C) 2002 Free Software Foundation, Inc.
    This file is part of GNU Bison.
    GNU Bison is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2, or (at your option)
    any later version.
    GNU Bison is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with Bison; see the file COPYING. If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
    What I need the spell checker to do is read each word, and strip any beginning or ending punctuation, e.g. (c) would become c. Pretty much punctuation consists of anything that is not a letter, hence the use of isLetter. I can easily modify the method to remove all punctuation using regular expressions, but I only want the beginning and end characters removed.
    Example of words:
    -yacc.c would become yacc.c and is not in the dictionary so it would be printed.

  • Problem with String to Int conversion

    Dear Friends,
    Problem with String to Int conversion
    I am having a column where most of the values are numeric. Only 4 values are non numeric.
    I have replaces those non numeric values to numeric in order to maintain the data type.
    CASE Grade.Grade  WHEN 'E4' THEN '24'  WHEN 'E3' THEN '23'  WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade  END
    This comes the result as down
    Grade
    _0_
    _1_
    _10_
    _11_
    _12_
    _13_
    _14_
    _15_
    _16_
    _17_
    _18_
    _19_
    _2_
    _20_
    _21_
    _22_
    _23_
    _24_
    _3_
    _4_
    _5_
    _6_
    _7_
    _8_
    _9_
    Refresh
    Now I want to convert this value to numeric and do some calculation
    So I changed the formula as below
    cast (CASE Grade.Grade  WHEN 'E4' THEN '24'  WHEN 'E3' THEN '23'  WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade  END as INT)
    Now I get the following error
    View Display Error
    _     Odbc driver returned an error (SQLExecDirectW)._
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    _State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1722, message: ORA-01722: invalid number at OCI call OCIStmtFetch. [nQSError: 17012] Bulk fetch failed. (HY000)_
    SQL Issued: SELECT cast ( CASE Grade.Grade WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' ELSE Grade.Grade END as Int) saw0 FROM "Human Capital - Manpower Costing" WHERE LENGTH(CASE Grade.Grade WHEN 'E1' THEN '20' WHEN 'E2' THEN '21' WHEN 'E3' THEN '22' WHEN 'E4' THEN '23' ELSE Grade.Grade END) > 0 ORDER BY saw_0_
    Refresh
    Could anybody help me
    Regards
    Mustafa
    Edited by: Musnet on Jun 29, 2010 5:42 AM
    Edited by: Musnet on Jun 29, 2010 6:48 AM

    Dear Kart,
    This give me another hint, Yes you are right. There was one row which returns neither blank nor any value.
    I have done the code like following and it works fine
    Thanks again for your support
    Regards
    Code: cast (CASE (CASE WHEN Length(Grade.Grade)=0 THEN '--' ELSE Grade.Grade END) WHEN 'E4' THEN '24' WHEN 'E3' THEN '23' WHEN 'E2' THEN '22' WHEN 'E1' THEN '21' when '--' then '-1' ELSE Grade.Grade END as Int)

  • Interesting problems with the 1.2.2 Debugger and String.substring(int)

    Guys/Gals,
    Here's an interesting problem to ponder...
    I define the following values in my class:
    private String descriptorClassName = null;
    private String userObjectClassName = null;
    private String name = null;
    I run the following piece of code as part of the constructor:
    descriptorClassName = this.getClass().getName();
    userObjectClassName = descriptorClassName.substring(0, descriptorClassName.indexOf("Descriptor"));
    name = userObjectClassName.substring(userObjectClassName.lastIndexOf(".")+1);
    The first line assigns the value of "com.foo.user.UserDataDescriptor" to descriptorClassName.
    The second line assigns the value of "com.foo.user.UserData" to userObjectClassName.
    The third line assigns the value of "UserData" to name.
    As I step through the code, I see the first two values being set, and yet the third value for name is reported by the debugger as:
    "name = null".
    I added a call to log4j, which reports that that value of name has been correctly set!
    This seems to be a result of the String.substing(int) call, as the call to Sring(substring(int, int) is fine.
    Has anyone come accross this one before?
    Does anyone have any workarounds other than:
    name = userObjectClassName.substring(userObjectClassName.lastIndexOf(".")+1, userObjectClassName.length());
    Cheers all.
    Regards,
    Chris.

    I've been trying to reproduce this problem and it always works perfectly. The debugger tells me that name = "UserData". I'm using JDev 3.2.2 and my project is using JDK1.2.2_JDeveloper. Here's the exact source code I'm trying.
    package com.foo.user;
    public class UserDataDescriptor {
    private String descriptorClassName = null;
    private String userObjectClassName = null;
    private String name = null;
    public UserDataDescriptor() {
    descriptorClassName = this.getClass().getName();
    userObjectClassName = descriptorClassName.substring(0, descriptorClassName.indexOf("Descriptor"));
    name = userObjectClassName.substring(userObjectClassName.lastIndexOf(".")+1);
    System.out.println("end of constructor");
    public static void main(String[] args) {
    UserDataDescriptor userDataDescriptor = new UserDataDescriptor();
    null

  • String to Int and Int to String

    How can I convert a string to Int & and an Int to String ?
    Say I've
    String abc="234"
    and I want the "int" value of "abc", how do I do it ?
    Pl. help.

    String.valueOf(int) takes an int and returns a string.
    Integer.parseInt(str) takes a string, returns an int.
    For all the others long, double, hex etc. RTFM :)

  • String to int conversion

    can n e body tell me how can i convert a String to an int

    always remember to use the try/catch block with thins that throw exceptions
    String gg;
    int in;
    try{  
    gg = "30";
       in = Integer.parseInt(gg);
    catch(NumberFormatException e){ 
      e.printStackTrace();
    }Ant

  • How to read a C structure with string and int with a java server using sock

    I ve made a C agent returning some information and I want to get them with my java server. I ve settled communication with connected socket but I m only able to read strings.
    I want to know how can I read strings and int with the same stream because they are sent at the same time:
    C pgm sent structure :
    char* chaine1;
    char* chaine2;
    int nb1;
    int nb2;
    I want to read this with my java stream I know readline methode to get the first two string but after two readline how should I do to get the two int values ?
    Any idea would be a good help...
    thanks.
    Nicolas (France)

    Does the server sent the ints in little endian or big endian format?
    The class java.io.DataInputStream (with the method readInt()) can be used to read ints as binary from the stream - see if you can use it.

  • Please help me with my code (has conversion from string to int)

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    public class Test3 extends MIDlet implements CommandListener
    {   Form mForm;
        Command mCommandQuit;
        Command mCommandItem;
        TextField input,prime1,prime2,prime3,output;
        Display mDisplay;
        int i,j=0,k1,k2,p,q,b;
        //int [] current=new int [1000];
        String mstring,a="";
        String [] temp=new String [1000];
        public void startApp()
        {System.out.println("startApp");
         mForm=new Form("RSA Encryption");
         mCommandQuit=new Command("QUIT",Command.EXIT,0);
         mCommandItem=new Command("ENCRYPT",Command.ITEM,0);
         mForm.append("Enter text:\n");
         input=new TextField(null,"",100, TextField.ANY);
         mForm.append(input);
         mForm.append("Enter first prime number(p):\n");
         prime1=new TextField(null,"",100, TextField.ANY);
         mForm.append(prime1);
         mForm.append("Enter second prime number(q):\n");
         prime2=new TextField(null,"",100, TextField.ANY);
         mForm.append(prime2);
         mForm.append("Enter d:\n");
         prime3=new TextField(null,"",100, TextField.ANY);
         mForm.append(prime3);
         mForm.addCommand(mCommandQuit);
         mForm.addCommand(mCommandItem);
         mDisplay=Display.getDisplay(this);
         mDisplay.setCurrent(mForm);
         mForm.setCommandListener(this);
        public void pauseApp()
        {System.out.println("pauseApp");
        public void destroyApp(boolean unconditional)
        {System.out.println("destroyApp");
        public void commandAction(Command c, Displayable d)
        {System.out.println("commandAction");
         if(c==mCommandQuit)
            notifyDestroyed();
         else if(c==mCommandItem)
         {p = Integer.parseInt(prime1.getString());
             q = Integer.parseInt(prime2.getString());
             b = Integer.parseInt(prime3.getString());
             //breaking up of big string into ints
             mstring=input.getString();
             temp[0]="";
             for(i=1;i<mstring.length();i++)
                {if (mstring.charAt(i) == ' ')
                    {j++;
                     temp[j]="";
                 else
                    {temp[j]=temp[j]+mstring.charAt(i);
             mForm.append("\n\nThe array is:\n");
             for(i=0;i<temp.length && temp!=null;i++)
    {k1=Integer.parseInt(temp[i]); ***********************
    k2=k1;
    for(j=1;j<b;j++)
    {k1=k1*k2;
    k1=k1 %(p*q);
    k2=k1 %(p*q);
    a=a+new Character((char)k2).toString();
    output=new TextField(null,a,100, TextField.ANY);
    mForm.append(output);
    }hi
    this code basically takes an input of string like " 179 84 48 48 155 " (with spaces)
    then it creates smaller strings in an array like "179","84","48","48","155" without the spaces
    then it creates int values 179,84,48,48,155 and finally after some math functions it prints the corresponding letters.
    the problem is that it is not printing the letter because of some exceptions-->java.lang.NumberFormatException .it comes in the line where i have put stars
    could anybody please help me print the letters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    thanks for all ur help guys, but me and my team member solved it on our own. here is the new code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    public class Test3 extends MIDlet implements CommandListener
    {   Form mForm;
        Command mCommandQuit;
        Command mCommandItem;
        TextField input,prime1,prime2,prime3,output;
        Display mDisplay;
        int i,j=0,l,k1,k2,p,q,n,b;
        String mstring,a = "";
        String [] temp=new String [1000];
        public void startApp()
        {System.out.println("startApp");
         mForm=new Form("RSA Encryption");
         mCommandQuit=new Command("QUIT",Command.EXIT,0);
         mCommandItem=new Command("DECRYPT",Command.ITEM,0);
         mForm.append("Enter text:\n");
         input=new TextField(null,"",100, TextField.ANY);
         mForm.append(input);
         mForm.append("Enter first prime number(p):\n");
         prime1=new TextField(null,"",100, TextField.NUMERIC);
         mForm.append(prime1);
         mForm.append("Enter second prime number(q):\n");
         prime2=new TextField(null,"",100, TextField.NUMERIC);
         mForm.append(prime2);
         mForm.append("Enter d:\n");
         prime3=new TextField(null,"",100, TextField.NUMERIC);
         mForm.append(prime3);
         mForm.addCommand(mCommandQuit);
         mForm.addCommand(mCommandItem);
         mDisplay=Display.getDisplay(this);
         mDisplay.setCurrent(mForm);
         mForm.setCommandListener(this);
        public void pauseApp()
        {System.out.println("pauseApp");
        public void destroyApp(boolean unconditional)
        {System.out.println("destroyApp");
        public void commandAction(Command c, Displayable d)
        {System.out.println("commandAction");
         if(c==mCommandQuit)
            notifyDestroyed();
         else if(c==mCommandItem)
         {p = Integer.parseInt(prime1.getString());
             q = Integer.parseInt(prime2.getString());
             b = Integer.parseInt(prime3.getString());
             n=p*q;
             //breaking up of big string into ints
             mstring=input.getString();
             temp[0]="";
             for(i=1;i<mstring.length();i++)
                {if (mstring.charAt(i) == ' ')
                    {j++;
                     temp[j]="";
                 else
                    {temp[j]=temp[j]+mstring.charAt(i);
             l=j;
             mForm.append("\n\nThe result is:\n");
             for(i=0;i<l;i++)
                {k1=Integer.valueOf(temp).intValue();
    k2=k1;
    for(j=1;j<b;j++)
    {k2=k2*k1;
    k2=k2 %n;
    k1=k2 %n;
    a=a+new Character((char)k1).toString();
    output=new TextField(null,a,100, TextField.ANY);
    mForm.append(output);

  • How to convert String to int in JSP?

    Hi,
    I set a session attribute in Servlet and want use it in JSP, How can I convert it to int or Integer?
    the line in my code doesn't work:
    int quantity=(int)session.getAttribute("vehiclequantity") ;
    Thanks in advance.
    Wolf
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    <HTML>
    <HEAD>
    <TITLE>Using the for Statement</TITLE>
    </HEAD>
    <BODY>
    <H1>Using the for Statement</H1>
    <%=session.getAttribute("vehiclequantity") %>;
    <%
    int loopIndex;
    int quantity=(int)session.getAttribute("vehiclequantity") ;
    out.println(quantity);
    for (loopIndex = 1; loopIndex <=2; loopIndex++) {
    out.println("This is iteration number "
    + loopIndex + "<BR>");
    %>
    </BODY>
    </HTML>

    Learning how to read errors and understand them will help you solve your problems quicker by yourself... So lets take a look at the error and classes involved...
    The error says:
    "Cannor Resolve Symbol: method valueOf(java.lang.Object) in the class java.lang.Integer" and gives you line line where the error occurs: Integer quantity = Integer.valueOf(session.getAttribute("vehiclequantity"));
    Now, if we look at the API for the Integer we notice that are are only two valueOf methods: valueOf(java.lang.String s) and valueOf(java.lang.String s, int radix). Not valueOf(java.lang.Object) method.
    Now we look at the getAttribute(java.lang.String name) method of HttpSession we see that the method returns a java.lang.Object. Now, you know you put a java.lang.String into that attribute, but the get method returns an Object. This is because you could have put any object in there, an Integer, a String, or some other class instance. But you know it is a String, so you can cast the returned value to a String, so that you will be calling the valueOf(java.lang.String s) method of Integer with the Object returned from the HtttpSession's getAttribute(java.lang.String name) method:
    Integer quantity = Integer.valueOf((String)session.getAttribute("vehiclequantity"));

  • Kinda urgent    please help pass strings to doubles and strings to ints

    Need to know how to pass strings to doubles and strings to ints
    and to check if a string is null its just if (name == null;) which means black right?
    like size as a string and then make the string size a double

    cupofjava666 wrote:
    Need to know how to pass strings to doubles and strings to ints
    and to check if a string is null its just if (name == null;) which means black right?
    like size as a string and then make the string size a doubleThink he means blank.
    Check the Wrapper classes (Double, Integer) in the api.
    parseInt() parseDouble() both take a string and return a primitive.
    String s = null;
    if(s == null) should do the trick!
    Regards.
    Edited by: Boeing-737 on May 29, 2008 11:08 AM

  • Checking a value...String OR int

    checking a value...String OR int
    how to check a given value whether it is a String OR int
    if(jTextField1.getText()...) is a String
         System.out.println("String");
    else //if it an int
         System.out.println("int");
    How can i check this...
    pls,tell.

    getText of JTextField ALWAYS returns a String.
    You can do this to see if it could be interpreted as an int:
    String theText = jTextField1.getText();
    try
       int theInt = Integer.parseInt(theText);
       System.out.println("int");
    catch (NumberFormatException ex)
       System.out.println("String");
    }If it isn't in a form that can be parsed as an int, you will get an exception and the catch block will get executed.

  • How can i cast array of string to int ?

                       while(st.hasMoreTokens()){
                                  test[count] = st.nextToken();
                                  count++;
                          }Since token deal with string, i have to pass them into String of array, but how can i convert all of them to int to perform arithmetic operation?

         public static void main (String[] args) throws IOException{
               DataInputStream dis = null;
                 String dbRecord = null;
                 int tokenCount = 0;
                 int numOfQuestion = 0;
                 int questionnAireNum = 0;
                 int postCode = 0;
                 int age = 0;
                 int gender = 0;
                 String [] response = new String[10];
                    File f = new File("polldata.txt");
                    FileInputStream fis = new FileInputStream(f); 
                    BufferedInputStream bis = new BufferedInputStream(fis); 
                    dis = new DataInputStream(bis);
                    // read the first record of the database
                    while ( (dbRecord = dis.readLine()) != null) {
                       StringTokenizer st = new StringTokenizer(dbRecord, ",");
                       tokenCount = st.countTokens();
                       numOfQuestion = tokenCount-4;
                       String rquestionNum = st.nextToken();
                       questionnAireNum = Integer.parseInt(rquestionNum);
                       String rpostCode = st.nextToken();
                       postCode = Integer.parseInt(rpostCode);
                       String rAge  = st.nextToken();
                       age = Integer.parseInt(rAge);
                       String rGender = st.nextToken();
                       gender = Integer.parseInt(rGender);
                       for(int i=0; i<numOfQuestion;i++){
                            response[i] = st.nextToken();
                       }hi how come when i cast the string as int it prompt me error as shown below ? I wonder what causes this because this is normally how i cast string to int, somehow it won work this way with token.
    Exception in thread "main" java.lang.NumberFormatException: For input string: " 3"
         at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
         at java.lang.Integer.parseInt(Integer.java:447)
         at java.lang.Integer.valueOf(Integer.java:553)
         at test.main(test.java:43)

  • Javascript, string to int

    Dear Sir:
    I try to convert string to int in flash javascript:
    temp="120";
    temp2="140";
    temp3=int ( temp );
    but I got a message "int is not a function", can somebody tell me how to do this?
    also, what if I want convert number back to string?
    thanks a lot!

    use:
    temp="120";
    temp2="140";
    temp3=Number ( temp );
    // to convert to a string, use:
    var temp4:String=String(temp3);
    // or
    var temp5:String=temp3.toString();

  • String into int & vice versa

    Hi all
    i cant convert the String into int although using
    Integer.parseInt & vice versa
    any ideas
    here is the code
    // fontCB & styleCB & sizeCB are ComboBoxes
    String fontName,fontStyle,fontSize;
    int fontStyleInt=1,fontSizeInt=1;
    fontName                = (String)fontCB.getSelectedItem();
    fontStyle               = (String)styleCB.getSelectedItem();
    fontSize               = (String)sizeCB.getSelectedItem();
    try
    fontStyleInt      = Integer.parseInt(fontStyle);
    fontSizeInt      = Integer.parseInt(fontSize);
    catch (NumberFormatException nfe)
    System.out.println("I'm an error");
    Font fontTemp           = new Font(fontName,fontStyleInt,fontSizeInt);
    myTextArea.setFont(fontTemp);

    The getSelectedItem() method returns a type called "Object". Therefore, to convert it to a string, u have to use String.valueOf(fontCB.getSelectedItem);Font styles are integers, i.e. PLAIN=0, BOLD=1, ITALIC=2, BOLD & ITALIC =3
    So, u can do the following,
    String styles={"Plain","Bold","Italics","Bold and Italics"};
    styleCB=new JComboBox(styles);To get the appropriate style, all u have to do is:
    int style=styleCB.getSelectedIndex();As for the font size,
    int size=Integer.parseInt(String.valueOf(sizeCB.getSelectedItem()));I think u r having plans for a text editor. right?

Maybe you are looking for

  • Recipients cannot open my attachments. What to do?

    I'm sure this has been posted many times before, but I wasn't able to find anything pertaining to my situation after 10 minutes of browsing, so I'm just posting it again. Attachments I send out with the mac mail account (word, excel, pdf, jpf saved f

  • REQD for Fresh BAM Install 11.1.1.3.0 -Data labels missing issue

    Hi This information is relevant to anyone who is doing upgrading to 11.1.1.3.0. There are 2 options if you encounter the data labels missing on the Active Studio tab : (1) Switch to Jrockit -Edit setDomainEnv.sh in directory $MW_HOME/user_projects/do

  • Change UOM in Material master

    Hi friends, I have a material X in Plant ABC and Plant XYZ. I have no open PR's and PO's for those materials. I have received 10 Ea in Plant ABC on 10/20/09 ( Current stock is 10 ea in ABC)                    and 20 Ea in Plant XYZ on 11/12/2009.( Cu

  • Reinstalling CS-4 Creative Suite 4 Web Premium

    I had a technician help earlier but her shift is over .  I didn't see the CS4 suite in My Prgrams on the start up menu, so I opened my C drive and found it there, but CS4 was not in one program it is all seperated. I tried to open Dreamweaver individ

  • HOW  DO YOU GET TO ASK A QUESTION AND GET AN ANSWER ABOUT ADOBE

    HOW DO YOU GET ANSWER ABOUT ADOBE MESSING WITH EVERY THING I TRY AND DO ON MY COMPUTER IS THERE AWAY TO SET IT SO IT WILL NOT MESS WITH EVERYTHING I DO ? [edited by forum host - you have violated the Community Guidelines on acceptable language]