-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.java
More file actions
65 lines (42 loc) · 1.04 KB
/
program.java
File metadata and controls
65 lines (42 loc) · 1.04 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
import java.util.ArrayList;
public class program {
public void parse(String values, String delimiter, int numIndex)
{
if(values.substring(0, 1).equals(delimiter))
{
if(values.substring(values.length()-1).equals(delimiter))
{
//DO NOTHING
}
else
{
values = values + delimiter;
}
}
else
{
values = delimiter + values;
if(values.substring(values.length()-1).equals(delimiter))
{
//DO NOTHING
}
else
{
values = values + delimiter;
}
}
ArrayList<String> words = new ArrayList<String>(0);
String temp = values;
temp = temp.substring(1);
while(temp.indexOf(delimiter) != -1)
{
words.add(temp.substring(0, temp.indexOf(delimiter)));
temp = temp.substring(temp.indexOf(delimiter) + 1);
}
System.out.println(words.get(numIndex-1));
}
public static void main(String[] args) {
program object = new program();
object.parse("one;rohith;aditya", ";", 2);
}
}