You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+86Lines changed: 86 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -431,6 +431,8 @@ Decision Making in programming is similar to decision-making in real life. In pr
431
431
432
432
- A nested if is an if statement that is the target of another if or else. Nested if statements mean an if statement inside an if statement. Yes, java allows us to nest if statements within if statements. i.e, we can place an if statement inside another if statement.
433
433
434
+
Syntax Code :
435
+
434
436
```
435
437
class Class_name{
436
438
public static void main(String[] args){
@@ -467,6 +469,8 @@ class Class_name{
467
469
468
470
- The switch statement is a multiway branch statement. It provides an easy way to dispatch execution to different parts of code based on the value of the expression.
469
471
472
+
Syntax Code :
473
+
470
474
```
471
475
class Class_name{
472
476
public static void main(String[] arg){
@@ -502,6 +506,8 @@ Looping in programming languages is a feature which facilitates the execution of
502
506
503
507
- while Loop : A while loop is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. The while loop can be thought of as a repeating if statement.
- do-while loop : do while loop is similar to while loop with only difference that it checks for condition after executing the statements, and therefore is an example of Exit Control Loop.
521
527
528
+
Syntax Code :
529
+
522
530
```
523
531
do{
524
532
// code here
@@ -537,6 +545,84 @@ Jump Statements are those statements which are used to come out of a particular
537
545
538
546
Note : Proper code is beeng given in [loops.java](https://github.com/ackwolver335/Java-Coder/blob/main/loops.java) file above !
539
547
548
+
## Strings in JAVA
549
+
550
+
Strings are the type of objects that can store the character of values and in Java, every character is stored in 16 bits i,e using UTF 16-bit encoding. A string acts the same as an array of characters in Java.
551
+
552
+
### Ways to create a String :
553
+
554
+
- String Literals : This methods of creating string is used in a situation in order to make java more memory efficient, cause in this method objects of the strings are not created.
555
+
556
+
Syntax Code :
557
+
558
+
```
559
+
class Sample{
560
+
public static void main(String[] a){
561
+
String str1 = "Constant value String";
562
+
}
563
+
}
564
+
```
565
+
566
+
- Using new keyword : In these type of cases the JVM used to create seperate objects in normal heap memo while the literals are placed in the string constant pool. And the variable created together with the object in the heap (Non-pool).
567
+
568
+
Syntax Code :
569
+
570
+
```
571
+
class Sample{
572
+
public static void main(String[] a){
573
+
String s1 = new String("String inside Heap Non-Pool");
574
+
}
575
+
}
576
+
```
577
+
578
+
### Categories of String
579
+
580
+
-**String** : String is an immutable class which means a constant and cannot be changed once created and if wish to change , we need to create an new object and even the functionality it provides like toupper, tolower, etc all these return a new object , its not modify the original object. It is automatically thread safe.
581
+
582
+
Syntax Code :
583
+
584
+
```
585
+
String s1 = "String without Object"; // Method 1
586
+
String s2 = new String("String with Object !"); // Method 2
587
+
```
588
+
589
+
-**StringBuffer** : StringBuffer is a peer class of String, it is mutable in nature and it is thread safe class , we can use it when we have multi threaded environment and shared object of string buffer i.e, used by mutiple thread.
590
+
591
+
Syntax Code :
592
+
593
+
```
594
+
StringBuffer str_bfr = new StringBuffer("Buffered Mutable String");
595
+
```
596
+
597
+
-**StringBuilder** : StringBuilder in Java represents an alternative to String and StringBuffer Class, as it creates a mutable sequence of characters and it is not thread safe. It is used only within the thread , so there is no extra overhead , so it is mainly used for single threaded program.
598
+
599
+
Syntax Code :
600
+
601
+
```
602
+
StringBuilder str_build = new StringBuilder();
603
+
str_build.append("Ack Wolver"); // Adding some extras to the string
604
+
```
605
+
606
+
-**StringTokenizer** : StringTokenizer class in Java is used to break a string into tokens. A StringTokenizer object internally maintains a current position within the string to be tokenized. Some operations advance this current position past the characters processed.
607
+
608
+
Syntax Code :
609
+
610
+
`
611
+
StringTokenizer str1 = new StringTokenizer("Hello World! Having Space !"," ");
612
+
while(str1.hasMoreTokens())
613
+
System.out.println(str1.nextToken());
614
+
`
615
+
616
+
-**StringJoiner** : StringJoiner is a class in java.util package is used to construct a sequence of characters(strings) separated by a delimiter and optionally starting with a supplied prefix and ending with a given suffix.
0 commit comments