Deduplicate a string in java

java string 6 years, 2 months ago
import java.util.HashMap; public class DeduplicationOfString{ static String dedup(String inputStr, int chunkSize) { int chunks = 0; StringBuilder dedup = new StringBuilder(); for(int i = 0; i< inputStr.length();){ String str = inputStr.substring(i,i+chunkSize); if(dedup.indexOf(str) != -1){ int ind = dedup.indexOf(str); dedup.insert(dedup.indexOf(",", ind), "-"+chunks); } else{ dedup.append(str+"-"+chunks+","); } chunks++; i+=chunkSize; } return dedup.toString(); } static String redup(String deduplicatedStr, int chunkSize) { String str = ""; for(int i = 0; i< deduplicatedStr.length();i++) { String str1 = deduplicatedStr.substring(i, i + chunkSize); int chunkIndex = deduplicatedStr.indexOf(",",i+chunkSize); String chunk = deduplicatedStr.substring(i+chunkSize, chunkIndex); System.out.println(chunk); } return ""; } public static void main(String[] args) { String dedupStr = dedup("abcdeabcdfabcde", 5); System.out.println(dedupStr); //redup(dedupStr, 5); } }
2533
Posted By
8080 port already taken issue when trying to
Open CMD with Administrator

1. Check what processes are running at a
java
ashokrebel007 ashokrebel007
Fibonacci Series in java
class Fibonacci { 
    static int fib(int n) 
    { 
java fibonacci
Reshma
Tower Of Hanoi
class Toh
{ 
    static void towerOfHanoi(int n, char
java tower of hanoi
Reshma
Permutations of a Given String
public class Permutation { 
    public static void main(String[] arg
    { 
java permutation
Reshma
Overloading In Java
public class Sum
{ 
    public int sum(int x, int y) 
java overloading
Reshma
Factorial of a Number
class Test 
{ 
    static int factorial(int n) 
java factorial
Reshma
Prime Number in Java
import java.util.*; 
class PrimeNumber
{ 
java prime number
Reshma
Reversing a String in Java
import java.lang.*; 
import java.io.*; 
import java.util.*; 
java reverse string
Reshma
Armstrong Number in Java
public class Armstrong 
{ 
    int power(int x, long y) 
java armstrong number
Reshma
Palindrome in java
class PalindromeExample
{  
 public static void main(String args[])
java palindrome
Reshma
String Palindrome in java
public class Palindrome
{
    public static void main(String args[
java string palindrome
Reshma
Comments executed
public class Testing { 
    public static void main(String[] arg
     { 
java comments
Reshma
While opening eclipse getting java virtual ma
First we have to check is java successfu
java -version
if its successfully installed, check you
java eclipse
srija srija
Finalize example
public class FinalizeExample {
    public void finalize() {
    System.out.println("Finalize is call
java
srija srija
How to create custom exceptions in java
public class customException extends Exc

    public customException(String messag
java
srija srija
Finding anagram
import java.util.Arrays;

public class StringAnagram {
java string anagram
itulasi
How to clean maven in java
mvn clean install
Maven java
Reshma
Read application.properties Using the Environ
import org.springframework.beans.factory
import org.springframework.core.env.Envi
import org.springframework.web.bind.anno
java application.properties environment autowired
Reshma
Reading application.properties with @Value An
import org.springframework.beans.factory
import org.springframework.beans.factory
import org.springframework.web.bind.anno
application.properties java @value
Reshma
Reading application.Properties with @Configur
//AppProperties.java

import org.springframework.boot.context.
application.properties java @configurationproperties
Reshma