Get String from char array

Complete source code below will show you, how to get String from char array.

***********************************************************************
COMPLETE SOURCE CODE FOR : GetStringFromCharArray.java
***********************************************************************


public class GetStringFromCharArray
{
public static void main(String[]args)
{
//Create an array from char type that will store all character for a String
char[]allCharacter=new char[12];

//Set all value in created array
allCharacter[0]='H';
allCharacter[1]='e';
allCharacter[2]='l';
allCharacter[3]='l';
allCharacter[4]='o';
allCharacter[5]=' ';
allCharacter[6]='W';
allCharacter[7]='o';
allCharacter[8]='r';
allCharacter[9]='l';
allCharacter[10]='d';
allCharacter[11]='!';

//Get String from created char array
String resultString=new String(allCharacter);

//Print result
System.out.println(resultString);
}
}


***********************************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************************

Omit all white space in String

Complete source code below will show you, how to omit all white space in a String.

*******************************************************************
COMPLETE SOURCE CODE FOR : OmitWhitespaceInString.java
*******************************************************************


public class OmitWhitespaceInString
{
public static void main(String[]args)
{
//Create a String with whitespace
String a=" Eliminate white space in t h i s s t r i ng ";

//Get String length that base on numbers of character include whitespace
int temp=a.length();

//Create an int variable
int numbersOfLetter=0;

//Create loop to count the numbers of Letter
for(int i=0; i<temp; i++)
{
if(Character.isLetter(a.charAt(i)))
{
numbersOfLetter++;
}
}

//Create an array base on numbers of letter that we get
char[]storeAllCharacter=new char[numbersOfLetter];

//Create an int variable
int temp3=0;

//Create loop to set each value in array
for(int i=0; i<temp; i++)
{
if(Character.isLetter(a.charAt(i)))
{
storeAllCharacter[temp3]=a.charAt(i);
temp3++;
}
}

//Get String from created char array
String resultStringAfterOmit=new String(storeAllCharacter);

//Print result
System.out.println(resultStringAfterOmit);
}
}


*******************************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************************

Get numbers of character in a string

Complete source code below will show you, how to get numbers of character that contain in a String. If you compile and execute source code below, you will get numbers of character is equal to 15 not 14. This is because the whitespace in a String also count.

***********************************************************************
COMPLETE SOURCE CODE FOR : GetNumbersOfCharacterInAString.java
***********************************************************************


public class GetNumbersOfCharacterInAString
{
public static void main(String[]args)
{
//Create a String
//You can change to other String that you want
String a="Hello everybody";

//Get numbers of character in created String and store it in int variable
int numbersOfCharacter=a.length();

//Print result
System.out.println("Numbers of character is : "+numbersOfCharacter);
}
}


***********************************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************************

Compare String ignore capital or ordinary letters

Complete source code below will show you, how to compare two string with same characteristic but ignore about capital or ordinary letters. The characteristic that i mean here is, number of characters and sequence of characters. We will use method equalsIgnoreCase().

****************************************************************************
COMPLETE SOURCE CODE FOR : CompareStringIgnoreCapitalOrOrdinaryLetters.java
****************************************************************************


public class CompareStringIgnoreCapitalOrOrdinaryLetters
{
public static void main(String[]args)
{
//Create first String = aaAAA
//You can try other string that you want by change aaAAA
String firstString="aaAAA";

//Create second String = AAaaa
//You can try other string that you want by change AAaaa
String secondString="AAaaa";

//Check if first String is same or not to second String
if(firstString.equalsIgnoreCase(secondString))
{
//If first String equal to second String, it will print ( firstString is same to secondString )
System.out.println("firstString is same to secondString");
}
else
{
//If first String not equal to second String, it will print ( firstString is not same to secondString )
System.out.println("firstString is not same to secondString");
}
}
}


****************************************************************************
JUST COMPILE AND EXECUTE IT
****************************************************************************

Compare String in java

Complete source code below will show you, how to compare two string with same characteristic. The characteristic that i mean here is, number of characters, sequence of characters and ordinary letters or capital letters. We will use method equal(). In the next post, i will show you how to compare two string that ignore about ordinary letters or capital letters.

*************************************************************************
COMPLETE SOURCE CODE FOR : CompareString.java
*************************************************************************


public class CompareString
{
public static void main(String[]args)
{
//Create first String = AAaaa
//You can try other string that you want by change AAaaa
String firstString="AAaaa";

//Create second String = AAaaa
//You can try other string that you want by change AAaaa
String secondString="AAaaa";

//Check if first String is same or not to second String
if(firstString.equals(secondString))
{
//If first String equal to second String, it will print ( firstString is same to secondString )
System.out.println("firstString is same to secondString");
}
else
{
//If first String not equal to second String, it will print ( firstString is not same to secondString )
System.out.println("firstString is not same to secondString");
}
}
}


*************************************************************************
JUST COMPILE AND EXECUTE IT
*************************************************************************
Related Posts Plugin for WordPress, Blogger...

I Also Can Create T-Shirt Logo For You