Skip to content

amitk432/Java-Basic-Questions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 

Repository files navigation

String and Collection Coding Challenges

Overview

This repository contains solutions to various String and Collection-related coding problems. Each problem is implemented in Java and includes examples to demonstrate functionality.

Table of Contents

πŸ”€ String Problems

  1. Reverse a String – Reverse a given string.
  2. Check if a String is Palindrome – Determine if a string is a palindrome.
  3. Count Occurrences of a Character – Count how many times a character appears in a string.
  4. Remove Duplicates from a String – Remove duplicate characters from a string.
  5. Find First Non-repeated Character – Identify the first character that appears only once.
  6. Check Anagram – Check if two strings are anagrams.
  7. Longest Palindromic Substring – Find the longest palindrome substring.
  8. Check if String Contains Only Digits – Verify if a string consists only of digits.
  9. Count Words in a String – Count the number of words in a given string.
  10. String Compression – Compress consecutive duplicate characters (e.g., "aabbbcc" β†’ "a2b3c2").
  11. Remove All Whitespaces from a String – Remove spaces from a given string.
  12. Replace All Occurrences of a Character – Replace all occurrences of a character with another.
  13. Find the Longest Word in a String – Identify the longest word in a sentence.
  14. Count Vowels and Consonants in a String – Count the vowels and consonants separately.
  15. Convert a String to a Character Array – Convert a string into an array of characters.
  16. Reverse Words in a String – Reverse the order of words in a sentence.
  17. Substring Search – Find the starting index of a substring.
  18. Remove Substring from a String – Remove a given substring from a string.
  19. String Equality (Case-insensitive) – Compare two strings without considering case.
  20. Find the Number of Occurrences of a Substring – Count how many times a substring appears.

πŸ”’ Collection Problems

  1. Find the Missing Number in an Array – Identify a missing number from 1 to n.
  2. Find Duplicate Elements in an Array – Detect duplicates in an array.
  3. Find the Maximum and Minimum in an Array – Find the highest and lowest values in an array.
  4. Sort an Array Using Collections.sort() – Sort a list of integers using Java’s Collections.sort().
  5. Merge Two Sorted Lists – Combine two sorted lists into one sorted list.
  6. Remove Null Elements from a List – Filter out null values.
  7. Check if a List Contains Duplicates – Detect duplicates using a set.
  8. Find the Intersection of Two Lists – Find common elements between two lists.
  9. Reverse a List – Reverse the order of elements in a list.
  10. Find the Second Largest Element in a List – Identify the second largest number.
  11. Find All Pairs with Given Sum in an Array – Find pairs whose sum equals a target number.
  12. Implement Stack Using Two Queues – Simulate a stack using queues.
  13. Queue Implementation Using Two Stacks – Simulate a queue using stacks.
  14. ArrayList vs LinkedList – Explain the differences between ArrayList and LinkedList.
  15. Create a Set from a List – Convert a list into a set (remove duplicates).
  16. Find Common Elements in Two Arrays – Identify common values in two arrays.
  17. Find Unique Elements in a List – Identify elements that appear only once.
  18. Sort a List of Strings by Length – Sort strings based on length.
  19. Find the Frequency of Each Element in a List – Count occurrences of each element.
  20. Convert a List to an Array – Convert a list into an array.
  21. Check if a List is a Sublist of Another List – Determine if one list is a subset of another.
  22. Remove Elements Divisible by 3 from a List – Remove all numbers divisible by 3.
  23. Find the Maximum Occurring Element in a List – Identify the most frequent element.
  24. Sum of Elements in a List – Calculate the total sum of a list.
  25. Check if a List is Empty – Verify if a list is empty.
  26. Shuffle a List – Randomly shuffle the elements of a list.
  27. Find the Union of Two Sets – Combine two sets.
  28. Find the Difference Between Two Sets – Identify elements in one set but not in another.
  29. Implement a Priority Queue – Create a priority queue.
  30. Count Elements Greater than a Given Value – Count how many numbers are greater than a specific value.

πŸ’» Installation & Usage

  1. Clone the repository
    git clone https://github.com/amitkumar-kellton/Java_Assignment.git

About

Java Sample codes for String and Collection

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages