Monday 16 December 2013

count occurrences of character in string in java



String s = "...";
int counter = 0;

 for( int i=0; i<s.length(); i++ )
{

if( s.charAt(i) == '@' )
{
counter++;
 }

 }

ArrayList in java

List<String> someList = new ArrayList<String>()
 // add "monkey", "donkey", "skeleton key" to someList

 someList.add(monkey1);
 someList.add(donkey2);
 someList.add(skeleton key3);
 someList.add(tesrt4);
 for(String item : someList )
 {

 System.out.println(item);

 }

How to add item to arraylist in java

How to add item to arraylist in java

List<String> someList = new ArrayList<String>()
 // add "monkey", "donkey", "skeleton key" to someList
someList.add(monkey1);
someList.add(donkey2);
someList.add(skeleton key3);
someList.add(tesrt4);

for(String item : someList )
{

 System.out.println(item);

 }

iterate through list java 

iterate through list using for each in java

 iterate through list using for each in java

List<String> someList = new ArrayList<String>()
 // add "monkey", "donkey", "skeleton key" to someList
someList.add(monkey1);
someList.add(donkey2);
someList.add(skeleton key3);
someList.add(tesrt4);

for(String item : someList )
{

 System.out.println(item);

 }



add comment block to methods in Eclipse

How to add comment block to methods in Eclipse..


Source -> Generate element comment

 

/**

*

*comment

*

*/

public void tets(){

 

}

Sunday 15 December 2013

An internal error occurred during: "Importing Maven projects". Unsupported IClasspathEntry kind=4 fixed

You might have used this command "mvn install" and then you have imported this project in to the eclipse.

 to solve this

 1)Right-click on your project, select Maven -> Remove Maven Nature.
 2)Open you terminal, go to your project folder and do “mvn eclipse:clean”
 3)Right click on your Project and select “Configure -> Convert into Maven Project” This is the error to solve this use above steps.









string-pattern-matched-in-java.html

Tuesday 10 December 2013

string pattern matched in java

string pattern in java

public class RegexMatches {
public static void main( String args[] ){
 // String to be scanned to find the pattern.
String line = "xxxx123@gmail.com";
String pattern = "@gmail.com";

if(line.endwith(pattern ))
{
 sysout("Matched");

     }else{
 sysout("Not Matched");
}
}
}

boolean check in if in java

boolean isS
if (status) { //positive work } else { // negative work }

Monday 9 December 2013

string is null or empty check in java

string null check in java

If we want to check weather string is empty or not then use the

String  str ="null";

if(str != null && !str.isEmpty())
{
 sysout("null");
}
else{
 sysout("not null");

}