Need to convert a long into a string, please

hi there
i need to convert a long into a string. can i just cast it like this:
(String)longNumber = some function that returns a long;

Why not just use Long.toString()? If you start with a long value, you can create a Long object and get it's value as a String.

Similar Messages

  • Converting a long to a string  (PLEASE HELP)

    I am trying to convert a long to a string so that I can put it into a vector. I have this:
    long fileSize = 0;
    String fileModDate = null;
    Vector fileList = new Vector();
         ~~~~~~~
    File [] files = myDir.listFiles();
    for (int i = 0; i<files.length; i++){
    fileSize = files.length();
    String s = fileSize.toString();
    //do the same for the mod date
    fileModDate = files[i].lastModified();
    When i try this, i get an error that long can not be dereferenced. Can anyone please help?

    There are two ways to solve this problem. You are trying to convert a primative type to a string without using its wrapper function (Long). So if you created a long variable as a (Long) object you could call its toString() method and this would work...
    The other way is to simply use the static method in the String class valueOf(long) as follows:
    String longString = String.valueOf(i);Hope this helps.
    Mark

  • Need to convert  Date from calendar to String in the format dd-mom-yyyy

    Need to convert Date from calendar to String in the format dd-mom-yyyy+..
    This is absolutely necessary... any help plz..
    Rgds
    Arwinder

    Look up the SimpleDateFormat class: http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
    Arwinder wrote:
    This is absolutely necessary... any help plz..For you maybe, not others. Please refrain from trying to urge others to answer your queries. They'll do it at their own pace ( if at all ).
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    (Yes I know it's on JavaRanch but I think it applies everywhere)
    ----------------------------------------------------------------

  • I need to insert an eof into a string

    I am using RandomAccessFile and I need to insert an EOF into a String manually. Any tips on how to do this? Here is a snippet of the code.
    origF.seek(0);
    replacement = "The stuff I want in the file.";
    replacement = replacement + ??????;  //(to indicate an EOF for the file)
    origF.writeBytes(replacement);
    origF.close();

    I found my way. Take a look in this piece of code.
        vlWrite.seek( vlPresentEntryPoint );  // position the file
        vlWrite.writeBytes( vpNewString );    // writes the new string
        vlWrite.writeBytes( vlSavedData );    // writes remaing file content
        vlWrite.setLength( vlFileLength );    // redifines file length
        vlWrite.close();I'm planning to share my code(s) in the forum. But me first make a concerning question. I'm new in Java and came to this forum to find and give help when I can. But, it is a forum where people wants to help and share or what ?????
    JJLobo

  • Convert an Object into a String

    Good day to everyone. I am trying to do a little coding in which a user will input his desired username. I want to check the database if the desired username of the current user is existing, so there'll be no duplication. I'm using JPA for the model and JSF for the controller and view.
    Here's my Model.
    @Entity
    public class WebUser implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
        private String lastName;
        private String firstName;
        private String middleName;
        private String username;
        private String password;
        public Long getId() {
            return id;
        public void setId(Long id) {
            this.id = id;
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (id != null ? id.hashCode() : 0);
            return hash;
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof WebUser)) {
                return false;
            WebUser other = (WebUser) object;
            if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
                return false;
            return true;
        @Override
        public String toString() {
            return "web.model.WebUser[id=" + id + "]";
        public String getLastName() {
            return lastName;
        public void setLastName(String lastName) {
            this.lastName = lastName;
        public String getFirstName() {
            return firstName;
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        public String getMiddleName() {
            return middleName;
        public void setMiddleName(String middleName) {
            this.middleName = middleName;
        public String getUsername() {
            return username;
        public void setUsername(String username) {
            this.username = username;
        public String getPassword() {
            return password;
        public void setPassword(String password) {
            this.password = password;
    }The controller and jsp are auto-generated from Netbeans. My question is, how will I convert the 'WebUser' object into a String so I can compare the value from input text to the value in the database?
    Here is my validation method inside WebUserController.java
    public void validateUsername(FacesContext facesContext, UIComponent component, Object value) throws ValidatorException {
            String newUsername = (String) value;
            System.out.println("new user name: " +newUsername);
            System.out.println("component: " +component);
            int webUserSize;
            StringBuffer sb = new StringBuffer();
            //webUsers.toString();
            if ((webUsers == null) || (webUsers != null)) {
                System.out.println("web users null");
                List<WebUser> allWebUsers = getWebUsers();
                webUserSize = allWebUsers.size();
                System.out.println("all web users: " +allWebUsers);
                System.out.println("size " +webUserSize);
                for(int i=1; i<=webUserSize; ++i) {
                    sb.append(allWebUsers);
                    System.out.println("username: " +sb.append(allWebUsers));
            }Honestly I'm new to java and having a hard time with this one. Hope someone can help me. Thanks a lot.
    I know my code is a mess. :(

    Thanks for the help guys! I used the "unique constraint" annotation of JPA and my problem is solved.
    Here's the code:
    @Entity
    @Table(
        name="WebUser",
        uniqueConstraints={@UniqueConstraint(columnNames={"username"})}
    public class WebUser implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
        private String lastName;
        private String firstName;
        private String middleName;
        private String username;
        private String password;
        public Long getId() {
            return id;
        public void setId(Long id) {
            this.id = id;
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (id != null ? id.hashCode() : 0);
            return hash;
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof WebUser)) {
                return false;
            WebUser other = (WebUser) object;
            if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
                return false;
            return true;
        @Override
        public String toString() {
            //return "web.model.WebUser[id=" + id + "]";
            return "web.model.User[username=" + username +"]";
        public String getLastName() {
            return lastName;
        public void setLastName(String lastName) {
            this.lastName = lastName;
        public String getFirstName() {
            return firstName;
        public void setFirstName(String firstName) {
            this.firstName = firstName;
        public String getMiddleName() {
            return middleName;
        public void setMiddleName(String middleName) {
            this.middleName = middleName;
        public String getUsername() {
            return username;
        public void setUsername(String username) {
            this.username = username;
        public String getPassword() {
            return password;
        public void setPassword(String password) {
            this.password = password;
    }Thanks again guys!

  • Need help converting quicktime movies into Flash files

    I need to convert a QT, PhotoJPEG compressed, movie file into a .flv format. I have AE 6.5 Standard and it keeps quitting on exporting a SWV file which would could probably get me by with my client. But, again, it errors out saying something like a JPG is busy, or a file is busy.
    I have FlipforMac,a purchased version. But I'm not sure if converting it into a .wmv and then a Flash file is the best route or is even possible.
    Any suggestions or ideas of software that I could purchase??
    ~reicko

    i don't think you have read up on the use of flash video
    (FLV). there's nothing you need that you do
    not already have (except maybe quicktime pro or some other
    video editing program). the FLV exporter
    comes FREE with flash 8. You should be able to open your
    quicktime movie in QT PRO and export to FLV
    format - then use any of the flash playback components for
    FLV files - best bet is to read the help
    docs on this subject and go to the devnet section of
    adobe.com where there are several in-depth
    articles about implementing flash video into your site.
    --> **Adobe Certified Expert**
    --> www.mudbubble.com
    --> www.keyframer.com
    rhian wrote:
    > Hi,
    > Thanks for your reply. I am using Flash 8. I've been
    looking into streaming
    > and it's very expensive with quicktime movies, however
    I've found a company
    > that will stream flash movies much more cheaply which is
    why I want to convert
    > it to a flash movie.
    >
    > Sorry are you say that Quicktime Pro allows you convert
    files into flash
    > formats?
    > Rhian
    >

  • How do i convert an object into a string?

    has said above, im trying to convert a object to a string.
    here is what i ahve so far:
    Object nodeInfo = node.getUserObject()

    RTFM
    Object o =...
    String str = o.toString();

  • Help I need to convert my movie into a SWF file

    Does anyone know how I can convert the movie into a swf file for flash?

    http://smallbusiness.chron.com/format-iphone-voice-recorder-use-57197.html
    ffiti wrote:
    In what format are raw Voice Memos files anyways?

  • Dummy Guide needed for converting AS2 code into AS3

    I have to convert my existing AS2 code into AS3, but I might as well be reading chinese. I never even began to learn AS3, it was still fairly new at the time and the class ended before we had an opportunity to even touch on it. My major was not web design, it was the print side of design. I took an additional class, after I graduated, to learn web design and our teacher told us, basically, that we were designers, not coders so we won't be getting much into actionscripting, beyond the basics. At the time I was relieved, but looking back, I really wish we would have gotten more into it. Bottom line, I need to learn now.
    Is there ANYONE that can help me out? I will list my code below, buy I am way beyond lost any help that can be provided, I would be so grateful!!!!
    On the main timeline I have the basic..
    stop(); -- I found the AS3 version, but I don't know what I'm looking at. I get "not_yet_set.stop()" and there are are 8 options I can choose from. I just want the timeline to stop until I tell it where to go next. And what is "not_yet_set"
    Then I have my buttons, which are, basically...
    on (release) {
    gotoAndStop("Home");
    Or "gotoAndPlay("Whatever");"
    I also have buttons for scrolling...
    on (press) {
    play();
    on (release) {
    stop();
    AND
    on (press) {
    _root.AboutMe_Controller.gotoAndPlay(…
    on (release) {
    _root.AboutMe_Controller.gotoAndStop(…
    For the on(release) command, this is what I found as the AS3 version: not_set_yet.dispatchEvent()

    because that's really as1 code, you have steeper learning curve than going from as2 to as3.
    first, remove all code from objects, assign instance names to your buttons and you can then start on as3:
    // so, if you name your home button, home_btn:
    home_btn.addEventListener(MouseEvent.CLICK,homeF);
    function homeF(e:MouseEvent):void{
    gotoAndStop("Home");
    p.s.  the not_yet_set stuff is there because you tried to use script assist or some other actionscript shortcut.

  • How can i convert JMS TextMessage into a String

    Please tell me,How can i convert A JMS TextMessage into a String

    http://java.sun.com/javaee/5/docs/api/javax/jms/TextMessage.html#getText()

  • I need help with Importing songs into Creative organizer please help!

    OK now i have a bunch of music files in my documents that all have MPEG4 with the itunes music symbol next to them. My problem is when i try to add them to my Windows media player nothing happens also when i search for the files in the Creative Import Wizard nothing shows up! Do i first need to put all the music i want on my ZVM im Windows Media Player first then add it's or is it something else? do i need to get rid of itunes entirely and just have the music files in my documents? Im really really confused please help!!!!!! Also No tracks show up when i try to add them to Windows Media Player or Creative MediaSource5 even though when i know i put them there
    P.S. What do u guys do ( I mean people with Zen Vison M's) Any know of any guides too? that would be great!Message Edited by Chrismic3 on 03-9-200705:54 PM
    Message Edited by Chrismic3 on 03-9-200706:00 PM

    bump

  • Need to convert long data type to varchar2

    I need to convert a long datatype in an existing table to a
    varchar2, in either another table or view. I have a 3rd party
    application which needs to query the data in the long data type,
    but it can "handle" the long.
    What is the best way to do this? I tried to make a trigger, but
    I must be missing something. Here is the trigger.
    CREATE OR REPLACE TRIGGER "PROD".SV_GET_RTG_COMNT
    BEFORE INSERT OR UPDATE ON PROD.RELS_RTG_SEQ_COMNT
    FOR EACH ROW
    WHEN (OLD.rels_rtg_no = NEW.rels_rtg_no)
    DECLARE
    -- DECLARE VARIABLES
    RTG_COMNT_VAR VARCHAR2(32);
    RTG_COMNT_LONG LONG;
    BEGIN
    Select COMNT_TXT into RTG_COMNT_LONG
    from rels_rtg_seq_comnt;
    RTG_COMNT_VAR := 'TEXT' || substr(RTG_COMNT_LONG,1,32);
    -- If INSERTING
    Insert into SV_RTG_SEQ_COMNT (print_cd, comnt_no,
    seq_no, rtg_no, comnt_txt) values
    (:new.print_cd, :new.comnt_no, :new.seq_no, :new.rels_rtg_no,
    rtg_comnt_var);
    END;
    I tried to use the substr command on the comnt_txt in view but
    received an invalid datatype error.
    Any help would be greatly appreciated.
    Doug

    create another table with clob datatype
    1)create table clob_tab(pkval number,clob_col clob);
    2) insert into clob_tab (select pkval,to_lob(long_col) from
    long_tab);
    3) use dbms_lob package to do string manipulation using
    substr,instr functions on clob column.

  • : how to convert string into uppercase string in java

    iam having string in lower case i need to convert it to uppercase using java.please help me

    s = s.toUpperCase ();See http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html.

  • Converting sql timestamp into a usable java format??

    hi there.
    does anyone know how to convert an sql timestamp into a usable java format? i have retrieved a timestamp from a mysql table in a jsp script and would like to convert it into the following format:
    12:42pm | 08.07.02
    as i understand it, i'll need to convert the timestamp into seconds since 1970 and then manipulate it as a calendar object? my first line is working, but i don't know what to do after...
    java.sql.Timestamp sqlTimestamp = resultSet.getTimestamp("date_and_time");
    next...?
    any help would be much appreciated!!
    thanks.

    please excuse my java sytnax ignorance, but i've tried a bunch of different syntax arrangements and can't figure out how to use the getTime() method. what comes after my first line there?
    java.sql.Timestamp sqlTimestamp = resultSet.getTimestamp("date_and_time");
    then something like:
    long msec=date.getTime(sqlTimestamp);
    but that doesn't seem to work...
    thanks for any help!

  • Making a Line into A String

    I need to make a horizontal line, a certian number of pixels long into a String or at least displayable in a label. How do you do it?

    The best would be to draw an image onto a label...

Maybe you are looking for

  • Ipad disabled says its locked and my mac won't open with the steps given

    I cannot get my friends ipad to sync with anything. It says its disabled and he doesn't know the password from the person he bought it from. He doesn't have a computer and I'm on a mac. I followed the steps given in the manuals section but it still w

  • Itunes is not working in windows 7

    I have followed the instructions contained in..... iTunes for Windows Vista, Windows 7, or Windows 8: Fix unexpected quits or launch issues" I started it in safe mode and found that it works.  So I then followed the steps to remove third-party plug-i

  • Cant open multiple profiles at the same time on Outlook.

    So i have done some research and found that you can use command line switches to open different profiles in Outlook. e.g. "C:\Program Files\Microsoft Office\Office15\OUTLOOK.EXE" /profiles "ProfileName" What i want to do is open two different profile

  • Problem's in data transfer  to target components in SAP PS - CATS

    Hi all I am trying to transfer data from CATS to PS and CO for month end closing . I have checked the budget in planned/actual/assigned report, and the WBS has sufficient budget. T-code used is CATA, and we are using a varient, and while transfering

  • Opening an external file containing javascript code

    I'm trying to develop a PDF in two languages. When pushing a button, all questions and list-of-values for possible answers should be translated. I created and initialized several variables with the two language phrases with javascript. Everything is