-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_String.java
More file actions
143 lines (108 loc) · 2.65 KB
/
Test_String.java
File metadata and controls
143 lines (108 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package com.newTest;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
public class Test_String
{
public static void testString()
{
String str="asd";
int num = str.indexOf('a');
System.out.println(num);
}
public static void accessOddChars()
{
String s = "strfgio";
for(int i= 0 ; i<s.length() ; i++)
{
if(i%2 != 0)
System.out.println("Chars at odd positions:- "+s.charAt(i));
}
}
public static void test_printUnique()
{
//Print aab;ccd;eef to ab cd ef
String str = "aab;ccd;eef";
String splitStr[] = str.split(";");
Set<Character> setChar = new LinkedHashSet<>();
char ch[] = null ;
//int k = 0;
String newString ="";
for(int i=0 ; i<splitStr.length ; i++)
{
String s= splitStr[i];
char chArr[] =s.toCharArray();
for(char c:chArr)
{
setChar.add(c);
}
}
for(char x:setChar)
{
newString += x;
System.out.println("Print String values:- "+newString);
}
// System.out.println(new String(ch));
}
public static void test_String()
{
String str ="aab;ccd;eef";
String splitStr[]= str.split(";");
for(String s: splitStr)
{
String strn = ""; //LOCAL VARIABLE
Set<Character> set = new LinkedHashSet<>(); //LOCAL VARIABLE
System.out.println(s);
for(int i=0 ; i<s.length() ; i++)
{
char c = s.charAt(i);
set.add(Character.valueOf(c));
}
Iterator<Character> iter = set.iterator();
while(iter.hasNext())
{
strn+=iter.next();
}
System.out.println("print string:- "+strn);
//set.clear();
System.out.println(set);
}
}
public static void test_s()
{
Character c = 'c';
String str = ""+c;
System.out.println(str);
}
//4th JUNE 2023
public static void repeatString()
{
String str = new String(new char[3]);
String repl = str.replace("\0", "great");
//Printing the below statement will print null since String object cannot be modified
//System.out.println(str);
System.out.println(str.replace("\0", "great"));
}
//check varargs operation
public static void check_varargs(int ...arr)
{
System.out.println(Arrays.toString(arr));
}
//8th JUNE 2023
public static void concatString()
{
String str = "abc";
System.out.println(str.concat("d"));
System.out.println(str);
}
public static void main(String[] args)
{
//testString();
//accessOddChars();
//test_printUnique();
//test_s();
test_String();
}
}