Jul 7, 2008

Java String Overview

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

free web hosting

Java String Overview

nhockhi
QUOTE
String Overview

Strings are sequences of Unicode characters. In many programming languages strings are are stored in arrays of characters. However, in Java strings are a separate object type, String. The "+" operator is used for concatenation, but all other operations on strings are done with methods in the String class.

See the Summary - Strings for an overview of the methods in String and related classes.
Related types and classes
String The basic class for strings. String objects can NOT be changed.
char Primitive type for 16-bit Unicode characters.
Character Primarily useful for its utility functions for working with characters.
StringBuffer StringBuffers are used to build or change strings. Conversion between String and StringBuffer is easy.
StringBuilder StringBuilder was added in Java 5. It is the same as StringBuilder, but slightly faster because it's unsynchronized.
StringTokenizer Used to break a String into tokens (words).
BufferedReader
BufferedWriter Useful for reading and writing text files.
Pattern, Matcher JDK 1.4 added java.util.Pattern and Matcher to do regular expression matching.
String literals

To write a constant string, put the characters between double quotes, eg "abc".
Escape Character

There are some characters that can't be written directly in a string. The backslash ('\') character preceeds any of these special characters. For example, if a string contains a double quotes, put a backslash ('\') in front of each internal double quote, eg "abc\"def\"ghi". The other most common escape character is the newline character, which is written as "n" following the backslash. For example, the following string will produces two output lines. Note that the compiler replaces the backslash plus character with the one desired character. Eg, "\n".length() is one.

System.out.println("This is the first\nand this is the second line.");

The "empty" string

The String equivalent of 0, is the string with no characters, "".
Concatenation
Expression Value
1 + 2 3
"1" + 2 "12"
1 + "2" "12"
"1" + 2 + 3 "123"
1 + 2 + "3" "33"

Putting two strings together to make a third string is called concatenation. In Java the concatenation operator is '+', the same operator as for adding numbers. If either operand is a String, Java will convert the other operand to a String (if possible) and concatenate the two.
Upper- and lowercase

To change to uppercase (and similarly to lowercase), Java has two methods, depending on whether you have a single character (eg, c) or a String (eg, s).
Converting a string to uppercase

s = s.toUpperCase();

Converting a character to uppercase

c = Character.toUpperCaseŠ;

Of course, you don't have to assign these values back to themselves -- you can use the values where you want.


Notice from mayank:
Copied it completely from here : http://leepoint.net/notes-java/data/string...ngoverview.html
2nd mistake in a day

 

 

 


Reply

derickkoo
QUOTE(nhockhi @ Aug 4 2006, 10:54 AM) *

Notice from mayank:
Copied it completely from here : http://leepoint.net/notes-java/data/string...ngoverview.html
2nd mistake in a day





well, that's true , String is a special Class in Java

Reply

darran
I have been programming with java for a few years and based on experience with String classes, what is being mentioned here is simply taken from most sites which teaches Java. Really basic stuff, and even so, this article has missed out on some crucial parts in the manipulation of String classes.

Namely, the use of String.indexOf(), String.charAt(), String.substring() and String.length(), all of which are extremely crucial especially if you want to do validation with emails, telephone number, password ... etc, these methods are extremely crucial.

Another thing would be the use of .equals() in conditional statements. For e.g. usually when we are comparing a variable to an integer

if (number1 == 20) {
System.out.println("The number is " + number1);
}

But it does not work in the case of Strings, for Strings the usage of .equals is required for it to check a condition.

if (string1.equals("hello")) {
System.out.println("The string is " + string1);
}

Hope you guys had learnt something from this.

 

 

 


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. java code convert string to a us phone number using regular expressions - 132.84 hr back.
  2. java diamonds codes escape characters examples - 457.79 hr back.
  3. java diamonds escape character example - 457.84 hr back.
Similar Topics

Keywords : java, string, overview

  1. Learn Java Programming Language Online Step By Step
    (0)
  2. Unexpected T_string In User.php [resolved]
    (5)
    Ok so i'm working on a site for my chruch, and i seem to be having a little bit of trouble with
    the user.php file i keep getting the following error: CODE Parse error: syntax error,
    unexpected T_STRING in /home/darkzone/public_html/test/user.php on line 195 and i was wondering
    if some one could help me with the script. session_start(); ob_start(); //Include the
    configurations include('config.php'); //Define a few variables $x = $_GET ;
    $u = $_GET ; class register { function displayform($title) { echo('....
  3. Java Object[][] Help
    (0)
    I'm having some issues with working with objects . I get an index out of bounds ex.
    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0 heres how
    I'm using it ---------------------------- Object contestants = new Object {}; contestants
    = "test"; any ideas appreciated. Do I need to specify the initial size on creation or something?
    It seems I answered my own question I gave it an inital size then I was able to add things. But is
    there a way I can add to it on the fly without knowing its require maximum size?....
  4. Free Java Hosting?
    (2)
    Hii.. just want to know if Trap17 provides the java(jdk)/jdbc/mysql as free hosting?? In case, it
    doesn't provide these. Can anyone guide me to a free java host? Thanks. Manu....
  5. Java Vs Javascript
    (11)
    I thought they were completely different things. Surely javascript should be seperated from the rest....
  6. Apache Tomcat And Java
    Will they run on package1/2 (0)
    Hi, Ive made a couple of Java servlets for a website and was wondering if it is possible to use them
    w/ the free hosting package is an application environment such as Tomcat? Dunk....
  7. Java Or C++
    (2)
    Many having tell me to make my MMORPG in java leads me to agree, But I'm not sure truly is it
    not yet easier, but yet the outcome of programming an MMORPG in java will make it fail or succeed
    more then one in C+= I've learned a lot of variables in javascript, and I don't think that
    java would be too bad either. My true question is, is those who use these languages, which seems
    to give better outcome, and which seems to be more in ease. Regards -PCessna....
  8. Budding Java Game Developers?
    Ever wanted to make your own java web-based game, but not had the time (8)
    Right, this is the first post of hopefully many in this thread. Basically the idea is to get many
    developers together to share ideas and knowledge to create our very own game. First we'll be
    asking for is any ideas of what kind of game everybody would like to make, and then we'll set
    about assigning tasks depending on everybodies skills. We will need programmers, artists,
    web-designers, even admin and marketing. This will be freeware, but the experience will be great.
    So, ideas anyone?....
  9. Java Applet Query
    (1)
    Hey there, I have made an applet that shows images moving about the screen. I have pause/resume
    buttons that work. But i've noticed that when the applet is interuppted by something i.e moving
    another window over it, it will automatically repaint. My question is how can I stop this? How can
    I make it so that the only time that paint is called is when I want it to be called? Thanks in
    advance!....
  10. Wysiwyg Jscript Editor
    I need a good Java Script Editor (3)
    Can any of you guys give me a good Java Script Editor. I really need one badly. I make Java Script
    goodies as an addon for my web site but it really takes a lot of my time to type all those similar
    code blocks over & over again, Could any one please provide me such an editor as Microsoft Visual
    Basic or Visual C++. I mean the IDE shold have similar features. ****Above all it should be a free
    one**** Thanks in adv. Dave....
  11. Java Updates On My Machine
    I have several versions (3)
    As per the following image, I have several java updates stored on my machine, and I wondered if the
    older ones could be deleted and have the java runtime perform okay? I'm simply trying to
    clean out a bunch of junk on my machine... make some HDD space.....
  12. Circular Movment/animation In Java?
    (6)
    Hey there guys! How would i go about making an object move about a fixed point for a java
    applet? Thanks in advance guys! Regards, Rod....
  13. Firefox Not Loading Java
    (1)
    I can't figure out why, but my Firefox hasnt been loading any Java applets. Instead it freezes
    up and goes to 'Not Responding'. Anyone know why this is happening and how to fix it? If it
    helps I'm running Vista.....
  14. Java Part 1
    (2)
    The HTML <script> tag is used to insert a JavaScript into an HTML page. Examples Write text
    with Javascript - http://www.w3schools.com/js/tryit.asp?filename=tryjs_text The example
    demonstrates how to use JavaScript to write text on a web page. Write HTML with Javascript -
    http://www.w3schools.com/js/tryit.asp?file...ryjs_formattext The example demonstrates how to use
    JavaScript to write HTML tags on a web page. How to Put a JavaScript Into an HTML Page CODE
    <html> <body> [color=red]<script type="text/javascript"....
  15. Java In A High School Software Design Course
    Is it good? (5)
    Hi, I'm doing a course called Software Design and Development for HSC in a high school in
    Australia. HSC is basically the courses you do that you get assessed on for University entrance. I
    haven't really done programming before, although I've seen source code and can decipher it
    and make small changes. I am also quite good with the general use of computers. One of the major
    projects we will do in the course is the making of a game (although it's not just game-making
    that we do. We also have to develop a software solution package, although I'm not su....
  16. Irc On Your Java Enabled Mobile!
    A breif tutorial describing how to access IRC on a Java enabled mobile (1)
    Before we go on please make sure that you have the following: Data Subscription on your Network
    with Support for Data Access from Java Apps. This could either be a GPRS Connection or a Wap
    connection. Whatever, it is, it is better to have a Traffic based Subscription rather than a Time
    based Subscription as chatting involves less traffic & more time. Generally, GPRS is billed Traffic
    wise whilst Wap is billed Time wise. Contact your Service Provider for more information. A phone
    with Java MIDP Support with Data Service Access & OTA Java App Installation & a max ja....
  17. Beginning Java
    where to start (10)
    does anyone know of any good websites with free java tutorials for people without a lot of prior
    coding experience? i've read some tutorials, but every one i read starts making references to C
    and C++... well i don't know either of those so it gets really really confusing really really
    fast. ive downloaded the sdk but that is it.... i know a pretty good amount of php and a tiny bit of
    perl but those are procedural languages so i dont know if they even helpe me at all with an OOP
    language like java.....
  18. Java Iterator Help
    I need help with a method using iterator (2)
    /** * Remove from the club's collection all members who * joined in the given month,
    and return them stored * in a sparate collection object. * @param month The month of the
    membership. * @param year The year of the membership. * @return The number of members.
    */ public ArrayList purge(int month, int year) { if(month >= 1 && month
    { Iterator it = members.iterator(); ArrayList purged;
    purged = new ArrayList(); int counter = 0; wh....
  19. Helpful Registry Edit For Java Programmers
    Command Prompt on right click menu (2)
    With this registry edit you can easily open the current folder in prompt without going through any
    Change Directory commands (cd). This is useful for people like me who are programming in JAVA, and
    every time to create class files and test them I have a diificult time just entering the commands in
    Prompt. But if you don't want to use this registry edit you can create the directory in
    C:\ drive like C:\files so you have to navigate very little in prompt. If you are
    experienced in regedit you can do it yourself shown below OR download the attachment and app....
  20. Jsp Or Java Chat Script Like Mig33
    (4)
    so most of you guys know mig33. its a wap application,probaly java.most kindly to be java. does
    anyone have java knowlege or knows where i can get a chat script like mig33? i also know this server
    supports jsp so im planing to use it for my application. i was hosted here last year but moved
    because i found a better host. now im back just to use the jsp on this server. Im planing to run
    chat applictions so if any one wants to help me in my project let me know.....
  21. The Power Of Java
    the best application that shows java features (14)
    Java technology has various usage from mobile applications to Enterprise applications. I think the
    power of Java technology in web applications and applets is showed in "meez.com" where u can create
    your own 3d avatars. /rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0"
    alt="rolleyes.gif" />....
  22. Problem With Java Script Popup Form
    Doesnt work in Safari (1)
    This code wont work in Safari, but works fine in Firefox 2. Can someone help. The error pops up
    however. It just doesn't do anything unless you dont pick one and then it says Pick a Windows
    tweak, but if you DO pick one it doesnt even try to load anything. Everything you see below is
    everything inside my PHP Include. If you would like to view my actual site it's
    http://boozkerstweaks.trap17.com There might be PHP errors and stuff right now, but i am working on
    those, but this i can not get. CODE <td  valign="top" class="right">
       ....
  23. Java Helpdesk
    All your queries regarding Java Programming goes here. (8)
    Hellow friends, I am creating this thread for all queries and suggestions related to java coding. If
    you face any problem, post it here, and others who have a solution can post the reply here. Hope it
    helps the users.....
  24. Hotspot Virtual Machine Exception_access_violation
    conflict between Sun Java and Windows (4)
    i was just messing around as usual on the net, and when i was closing everything down, i noticed
    this file on my desktop 'hs_err_pid3672' its a text file, i have no idea what it is and cant
    understand anything in it, but its kinda freakin me out, so i would appreciate anything you guys
    have to say about it CODE # # An unexpected error has been detected by HotSpot Virtual
    Machine: # #  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x7c9010f3, pid=3672,
    tid=1928 # # Java VM: Java HotSpot(TM) Client VM (1.5.0_06-b05 mixed mode, shar....
  25. Java Basic Program Guidance
    (6)
    aving some problems taking in the Java at Uni, Was wondering if anyone could shine some light on it
    for me. My task is to write a program that will ask you to enter 2 words. the program will then
    print out both words on one line. However the words will be seperated by dots that will make the
    total length of the line 40. so if your first word was turtle and the second was abc, the output
    would be turtle...............................abc The program should check for certain conditions:
    1. a word can not be longer than 37 characters; 2. there must always be atlest 2 do....
  26. How To Create Java Button Or Frame
    to be customized (12)
    hi to all!!!! just like to ask if it would be possible if i could make a custom
    button or frame in java. i got tired of using the build infeatures in java. i would like to create
    my own dessign of button or frame.. can it be possible!!! /biggrin.gif' border='0'
    style='vertical-align:middle' alt='biggrin.gif' /> thank!!!! /laugh.gif'
    border='0' style='vertical-align:middle' alt='laugh.gif' /> New Help In! is NOT a descriptive
    topic title. Next time you decide not to follow the posting rules, you will be issued a w....
  27. [help] Java Script: Window.open
    Works with Firefox, not IE (8)
    CODE <HEAD> var popUpWin=0; function popUpWindow(URLStr) {
     if(popUpWin)  {    if(!popUpWin.closed) popUpWin.close();  }
     popUpWin = open(URLStr, 'GunBound Tactics: Screenshots',
    'width=820,height=550,menubar=no,resizable=yes,scrollbars=yes,toolbar=no,top=90,left=90')
    ;; } </HEAD> <BODY> <a
    href="javascript:popUpWindow('/f11/clipped.php');"><b>Clips&
    #60;/b></a> This is a script for opening a new window. It works ....
  28. Java Script Drop Down Menu With Css
    - a full code for a dynamic drop down (2)
    Introduction This is a code that I use to dynamically create the drop down menus. First, you have
    to edit the following code and put it in your Javascript. Notice : /*** SET BUTTON'S FOLDER HERE
    ***/. Edit that to your folder. Also, the /*** SET BUTTONS' FILENAMES HERE ***/. This creates a
    mouseover when the drop down is activated. Put all your onmouseover images under: oversources = new
    array; and your onmouseout images under : upsources. Be sure to set your on and out images above
    each other. CODE /*** SET BUTTON'S FOLDER HERE ***/ var buttonFold....
  29. What Is A T_string?
    Please help! I'm new at PHP Programming (13)
    I'm new at PHP, and I looked for a while on here, and found some stuff I was looking for about
    form processing, and sending E-Mail through PHP. However, the script I just created won't work.
    I get the following error: Parse error: parse error, unexpected T_STRING in
    /home/hamtaro/public_html/send_feedback.php on line 9 Exactly what is a T_STRING? If I need to post
    my code, I will.....
  30. Java editor
    (72)
    In your opinion what's the best java editor/compiler? i use jcreator le and it works nicely.......

    1. Looking for java, string, overview

Searching Video's for java, string, overview
advertisement



Java String Overview



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE