Friday 18 October 2013

string split by space in java

How to split a String by space

str = "Hello I'm your String Hello";

String[] splited = str.split("\\s+");

string-pattern-matched-in-java

boolean check in if in java

boolean isStatus;
if (isStatus)
{
 //positive work
}
else
{
 // negative work
 }

string comparison in java

insted of "==" using for comparing String use always equals() method.

Easiest way to convert String to StringBuffer

 Easiest way to convert String to StringBuffer


stringbuffer vs stringbuilder

stringbuffer vs stringbuilder

StringBuffer is synchronized, StringBuilder is not.

remove last characters from a StringBuffer

remove last characters from a StringBuffer
public class StringBufferDelete {
    public static void main(String[] args) {
        String text = "mytechnologythought";
        StringBuffer sb = new StringBuffer(text);
        System.out.println("Original text  = " + sb.toString());
        sb.delete(0, 10);
        System.out.println("After deletion = " + sb.toString());
        sb.deleteCharAt(sb.length() - 1);
        System.out.println("Final result   = " + sb.toString());
    }
}

java HashMap Iterator

java HashMap Iterator
using for each loop

for (Map.Entry entry : hashMap.entrySet()) {
System.out.println("key,val: " + entry.getKey() + "," + entry.getValue());
}


How get current path in java system dir

many time we required to get current system dir path

String currentPath= System.getProperty("user.dir");











here is full example




public class Path {
                
            public static void main(String args[]) {
            
                String currentPath = System.getProperty("user.dir");
               System.out.println(" ");
                         System.out.println("Current working directory path in Java : " + currentPath);
            
            }
        }

java msql jdbc example

java msql jdbc example


create jar file from command prompt

create jar file from command prompt

 The fromat is :-

jar cf jarfile  .*
For Example :- jar cf test.jar .*

this will add all file and create test.jar


split by space in java

split by space in java

str.split("\\s+");

This will split by space.

how to create new line in html

how to create new line in html
Try this

<br>

Tag this will break line

Thursday 17 October 2013

how to get map key in java

Try this

Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}

How to Iterate Through a HashMap

Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}