Core java
- 17 May
Can we call run() method directly to start a new thread
No, you can not directly call run method to start a thread. You need to call start method to create a new thread. If you call run method directly , it won’t create a new thread and it will be in same stack as main. Lets understand with the help of example: [crayon-6743d99d24b07935718805/] When you […]
- 16 May
Can we start a thread twice in java
No, Once you have started a thread, it can not be started again. If you try to start thread again , it will throw IllegalThreadStateException Lets understand with the help of example: [crayon-6743d99d25f32113229859/] When you run above program , you will get below output: Thread is runningException in thread “main” java.lang.IllegalThreadStateException at java.lang.Thread.start(Thread.java:705) at org.arpit.java2blog.StartThreadAgainMain.main(StartThreadAgainMain.java:16) […]
- 15 May
Java String compareToIgnoreCase example
String’s compareToIgnoreCase method is similar to compareTo method. Only difference with compareTo is that it ignores cases.It also compares Strings lexigraphically. Both String get converted to unicode value and then compares. If you call str1. compareToIgnoreCase(str2) then if it returns positive number : str1 is greater than str2 0: str1 is equal to str2 negative number : str1 is […]
- 14 May
Java String equalsIgnoreCase example
String’s equalsIgnoreCase method is similar to equals method but it ignores case. So if Strings have different cases, then also it will considered as equals. For example: [crayon-6743d99d269f0566219522/] str1.equalsIgnoreCase(str2) will return true. Method Signature: [crayon-6743d99d269f5363870572/] String equalsIgnoreCase Example: [crayon-6743d99d269f7254332287/] When you run above program, you will get below output: [crayon-6743d99d269f9478736454/]
- 14 May
Java String equals example
String’s equals method compares String with specified object. It checks if both have same character sequence. It is generally used to compare two Strings. Method Signature: [crayon-6743d99d26ac5692201408/] String equals Example: [crayon-6743d99d26ac7033341028/] When you run above program, you will get below output: [crayon-6743d99d26ac8962071820/]
- 14 May
Java String contentEquals example
String’s contentEquals method is used to compare String with StringBuffer. It returns boolean datatype. Method syntax: [crayon-6743d99d26b61026859970/] String contentEquals Example: [crayon-6743d99d26b63335069336/] When you run above program, you will get below output: [crayon-6743d99d26b64589027469/] Please note that contentEquals method is case sensitive as you can see in above example
- 13 May
Java String endsWith example
String’s endWith method checks if String ends with specific suffix. It returns boolean datatype. Method syntax: [crayon-6743d99d26c09361018639/] String endsWith Example: [crayon-6743d99d26c0c869463710/] When you run above program, you will get below output: [crayon-6743d99d26c0d243662367/] Please note that endsWith method is case sensitive as you can see in above example
- 12 May
Java String startsWith example
String’s startsWith method checks if String starts with specific prefix. It returns boolean datatype. Method Signature: [crayon-6743d99d26caf855728123/] String startsWith Example: [crayon-6743d99d26cb1109388205/] When you run above program, you will get below output: [crayon-6743d99d26cb2539196949/] Please note that startsWith method is case sensitive as you can see in above example
- 12 May
Java String charAt example
String’s charAt method returns char value present at specified index. String is nothing but Sequence of char values and it starts with index 0. Method Signature: [crayon-6743d99d26d9a623583447/] String charAt Example: [crayon-6743d99d26d9d202567172/] When you run above program, you will get below output: [crayon-6743d99d26d9e519102535/]