Operations on Data String with length () and concat ()

 on Monday, September 2, 2013  

Still related with the post of Class String as you can read here, here's a post about the Class String again. The yesterday post unfinished .
Operations on the data string is a method or facility (better known in the Java method) provided by Java in the String Class to manipulate string data. Operations that can be performed by the String Class String data include:
  • Length of the data string
  • Merging two (2) or more data strings
  • Benchmarking data is string
  • Replacement string data
  • Capitalization of the letters in the data string, and
  • Operations Sub-String



Length of the data string or rather the large number of characters in a string can be identified by using the facility / method length (). Its more easy to understanding,by seing this following example code:

class length
{
public static void main (String [] args)
{
String x1 = new String ("test");
System.out.println ("Contents x1:" + x1);
System.out.println ("Length:" + x1.length ());
}
}

If you run the results will appear:
Fill x1: Trial
Length: 8
Why result 8? Though the number of letters that is only 7 instead? That's because it's also a space here counted.

Merging can be done with the data string method concat (). This method will create two different strings to create a string. This method together with the + operator. Typically, to combine more than two strings, use the + operator on the method print () and println (). More confused? We'll see the following example:

Join a class
{
public static void main (String [] args)
{
Z1 String = new String ("Darto");
System.out.println ("Content initial z1 =");
System.out.println ();
z1 = z1.concat ("Iwan Setiawan");
System.out.println ("Contents after z1 in concat =", + z1);
}
}



want to know the results? Try running ......
Operations on Data String with length () and concat () 4.5 5 Darto Iwan Monday, September 2, 2013 Still related with the post of Class String as you can read here, here's a post about the Class String again. The yesterday post unfini...


No comments:

Post a Comment

Silakan berkomentar ....