From f4068ca6128ac15ce9070398ade90e1ef39bb1e6 Mon Sep 17 00:00:00 2001 From: GauravWalia19 Date: Fri, 21 Dec 2018 08:43:30 +0530 Subject: [PATCH] added strings in java --- C/README.md | 15 +++++++ Java/Data-Structures/STRING/Strings.java | 51 ++++++++++++++++++++++++ Java/README.md | 8 ++++ datastructures.md | 7 ++++ docs/complexity.md | 34 +++++++++++++++- 5 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 Java/Data-Structures/STRING/Strings.java diff --git a/C/README.md b/C/README.md index 75d2657..9dde123 100644 --- a/C/README.md +++ b/C/README.md @@ -52,6 +52,21 @@ * DYNAMIC ARRAY * LINKED +#### TREES + +* BINARY TREE +* GENERIC TREES +* THREADED BINARY TREE +* XOR TREES +* BINARY SEARCH TREE +* AVL TREES +* RED BLACK TREES +* SPLAY TREES +* AUGMENTED TREES +* SCAPEGOAT TREES +* INTERVAL TREES +* HEAP TREE + #### HEAPS * [1D ARRAYS USING HEAPS](Data-Structures/HEAPS/dynamicarray.c) diff --git a/Java/Data-Structures/STRING/Strings.java b/Java/Data-Structures/STRING/Strings.java new file mode 100644 index 0000000..4ebcf44 --- /dev/null +++ b/Java/Data-Structures/STRING/Strings.java @@ -0,0 +1,51 @@ +public class Strings +{ + public static void main(String[] args) + { + /*USAGE OF STRING CLASS IN JAVA*/ + String trial = "Hello World this is github"; + + System.out.println("string:\t" + trial); + System.out.println(); + + System.out.println("METHODS IN STRING CLASS"); + + //charAt() + System.out.println("charAt(3):\t\t\t" + trial.charAt(3)); + + //indexOf() + System.out.println("indexOf('o'):\t\t\t" + trial.indexOf('o')); + System.out.println("indexOf('o',3):\t\t\t" + trial.indexOf('o',3)); + System.out.println("indexOf(\"this\"):\t\t" + trial.indexOf("this")); + System.out.println("indexOf(\"this\",3):\t\t" + trial.indexOf("this",3)); + + //lastIndexOf() + System.out.println("lastIndexOf('o'):\t\t" + trial.lastIndexOf('o')); + System.out.println("lastIndexOf('o',3):\t\t" + trial.lastIndexOf('o',3)); + System.out.println("lastIndexOf(\"this\"):\t\t" + trial.lastIndexOf("this")); + System.out.println("lastIndexOf(\"this\",4):\t\t" + trial.lastIndexOf("this",4)); + + //length() + System.out.println("length():\t\t\t" + trial.length()); + + //substring() + System.out.println("substring(1):\t\t\t" + trial.substring(1)); + System.out.println("substring(3,5):\t\t\t" + trial.substring(3,5)); + + //replace() + System.out.println("replace('a','b'):\t\t" + trial.replace('a','b')); + System.out.println("replace(\"Hello\",\"world\"):\t" + trial.replace("Hello","world")); + + //concat() + System.out.println("concat(\" Hello World\"):\t\t" + trial.concat(" Hello World")); + + //equals() + System.out.println("equals(\"Hello World this is github\"):\t" + trial.equals("hello wotld a bac a")); + + //toUpperCase() + System.out.println("toUpperCase():\t\t\t" + trial.toUpperCase()); + + //toLowerCase() + System.out.println("toLowerCase():\t\t\t" + trial.toLowerCase()); + } +} \ No newline at end of file diff --git a/Java/README.md b/Java/README.md index 908ac3b..3f40734 100644 --- a/Java/README.md +++ b/Java/README.md @@ -13,6 +13,10 @@ * [three dimensional array](Data-Structures/ARRAYS/threeDarray.java) * [four dimensional array](Data-Structures/ARRAYS/fourDarray.java) +#### STRING + +* [implementation with methods](Data-Structures/STRING/Strings.java) + #### LISTS * LINKED LIST @@ -38,6 +42,10 @@ * [Stack class](Data-Structures/STACKS/INBUILT-STACK/Stacks.java) * MISC STACKS +#### QUEUES + +#### TREES + ### :rocket: DYNAMIC PROGRAMMING ### :rocket: MISC diff --git a/datastructures.md b/datastructures.md index 6d6e6ea..b6e1c86 100644 --- a/datastructures.md +++ b/datastructures.md @@ -63,6 +63,13 @@ Indexer for Data Structures Lover * implementation * [C](C/Data-Structures/ARRAYS/jaggedarray.c) +### :octocat: STRING + +* blog +* docs +* implementation + * [JAVA](Java/Data-Structures/STRING/Strings.java) + ### :octocat: LISTS #### SINGLE diff --git a/docs/complexity.md b/docs/complexity.md index 887ace7..e2e66ca 100644 --- a/docs/complexity.md +++ b/docs/complexity.md @@ -61,6 +61,8 @@ This page contains the complexities of different algorithms in this repository. * ARRAY CLASS IN C++ * [MISC ARRAYS](#misc-arrays) * [JAGGED ARRAY](#jagged-array) + * [STRING](#string) + * [Strings in JAVA](#strings-in-java) * [LISTS](#lists) * SINGLE * [SINGULAR LINKED LIST](#singular-linked-list-having-head-and-next) @@ -99,11 +101,23 @@ This page contains the complexities of different algorithms in this repository. * HEAPED PRIORITY QUEUE * HASHTABLE * TREES + * BINARY TREE + * GENERIC TREES + * THREADED BINARY TREE + * XOR TREES + * BINARY SEARCH TREE + * AVL TREES + * RED BLACK TREES + * SPLAY TREES + * AUGMENTED TREES + * SCAPEGOAT TREES + * INTERVAL TREES + * HEAP TREE + * GRAPHS * HEAPS * [DYNAMIC 1D ARRAY](#dynamic-1d-arrays-(CC++)) * [DYNAMIC 2D ARRAY](#dynamic-2d-arrays-(CC++)) * [DYNAMIC 3D ARRAY](#dynamic-3d-arrays-(CC++)) - * GRAPHS * BLOCKCHAIN ## ALGORITHMS @@ -122,7 +136,7 @@ This page contains the complexities of different algorithms in this repository. #### :rocket: SORTING SNo. | Algorithm | Order of complexity O(n) | Type of Complexity | Stable/Unstable Sort | In Place Algorithm | Space Complexity - ---- | --------- | ------------------------ | ------------------ | -------------------- | ------------------ | ---------------- + ---- | --------- Data-Structures/STRING/Strings.java| ------------------------ | ------------------ | -------------------- | ------------------ | ---------------- 1 | Bubble Sort | O(n^2) | Quadratic | Stable / Can be Unstable** | :heavy_check_mark: | O(1) 2 | Selection Sort | O(n^2) | Quadratic | Unstable | :heavy_check_mark: | O(1) 3 | Insertion Sort | O(n^2) | Quadratic | Stable | :heavy_check_mark: | O(1) @@ -273,6 +287,22 @@ This page contains the complexities of different algorithms in this repository. ##### ARRAY CLASS IN C++ +### STRING + +#### Strings in JAVA + +SNo. | Methods | Order of complexity O(n) | Type of Complexity + 1 | char charAt() | O(1) | Constant + 2 | int indexOf() | O(n) | Linear + 3 | lastIndexOf() | O(n) | Linear + 4 | int length() | O(1) | Constant + 5 | substring() | O(n) | Linear + 6 | replace() | O(n) | Linear + 7 | concat(str) | O(n^2) | Quadratic + 8 | equals(str) | O(n) | Linear + 9 | toUpperCase() | O(n) | Linear + 10 | toLowerCase() | O(n) | Linear + ### LISTS #### SINGLE