AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL
HTML Tutorial

Java Strings


Java Tutorial » Java Strings

Strings, widely used in Java programming, are used for storing characters surrounded by double quotes.

In the below example, we create a variable of type string and then we assign it a value:
Example:
public class Main {
  public static void main(String[] args) {
    String greeting = "Hey, Hey man.";
  System.out.println(greeting);
  }
}
Output:
Hey, Hey man.

 


String Length


The length() method will return the number of characters that are contained in the string.

Example:
public class Main {
  public static void main(String[] args) {
    String my_txt = "agernic tutorial contain pretty good explanations";
    System.out.println("Text length of the string is: " + my_txt.length());
  }
}
Output:
Text length of the string is: 49


String Concatenation


Combine more strings using + operator is called concatenation:

This will returns a new string as string1 with string2 added to it at the end.

Example: use the + method
public class Main {
  public static void main(String args[]) {
    String Name = "Chris";
    String SurName = "Langford";
  System.out.println(Name + " " + SurName);
  }
}
Output:
Chris Langford
Note: we have added an empty text (" ") to create a space between mames.


We use the concat() method to concatenate two strings

Example: concat() method
public class Main {
  public static void main(String[] args) {
    String Name = "Chrys ";
    String SurName = "Store";
    System.out.println(Name.concat(SurName));
  }
}
Output:
Chrys Store


Finding a Character or character sequence in a String


In a specified text indexOf() method returns the index (position) in a string.

Example:
public class Main {
  public static void main(String[] args) {
    String my_txt = "please locate me where is the position of the word: me";
    System.out.println(my_txt.indexOf("me"));
  }
}
Output:
14




Java String to init, split, length, methods, format, array, contains, compare, equals, concatenation Java Strings imutable, substring, list, compare,
Java String - java

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


HTML Image tag, code...
How to code in HTML...
HTML text tag...
HTML text, how to display...
Container responsive styles...
HTML container tag...
HTML container...
Send forgot password by mail or message ...
PHP MySQL simple login system...
Check for duplicate username live or ema...
How to create simple search engine using...
Diseño de sitio web CSS Layout...
Diseño de caja flexible CSS3...
Botones en CSS...
ID y Clase, Diferencias entre Class e Id...
Esquina redondeada CSS...
Tamaño de caja css box-sizing: border-b...
Alineación CSS...
Altura y Anchura CSS...
Bordes CSS...